3 Commits
Author SHA1 Message Date
Artёm Mishin 74e28d9672 chore: Update 2025-05-26 05:04:39 +03:00
Artёm Mishin 0218c2131f chore: Update 2025-05-26 04:34:59 +03:00
Artёm Mishin de051ef362 chore: Rename package 2025-05-26 03:27:19 +03:00
5 changed files with 90 additions and 5 deletions

No files matched your search

+49 -1
View File
@@ -1,4 +1,4 @@
package universe_io
package uio
import (
"math"
@@ -30,6 +30,54 @@ type byteBuffer struct {
writerCursor Cursor
}
func (b *byteBuffer) WriteShortByteArray(data []byte) error {
if len(data) > 0xFFFF {
return ErrOutOfBounds.CreateEmpty()
}
if b.RemainingWriterBytes() < 2+len(data) {
return ErrOutOfBounds.CreateEmpty()
}
if err := b.WriteShortLE(int16(len(data))); err != nil {
return err
}
n, err := b.Write(data)
if err != nil {
return err
}
if n != len(data) {
return ErrOutOfBounds.CreateEmpty()
}
return nil
}
func (b *byteBuffer) WriteByteArray(data []byte) error {
if len(data) > 0xFFFFFFFF {
return ErrOutOfBounds.CreateEmpty()
}
if b.RemainingWriterBytes() < 4+len(data) {
return ErrOutOfBounds.CreateEmpty()
}
if err := b.WriteIntLE(int32(len(data))); err != nil {
return err
}
n, err := b.Write(data)
if err != nil {
return err
}
if n != len(data) {
return ErrOutOfBounds.CreateEmpty()
}
return nil
}
func (b *byteBuffer) WriteShortString(s string) error {
return b.WriteByteArray([]byte(s))
}
func (b *byteBuffer) WriteString(s string) error {
return b.WriteByteArray([]byte(s))
}
func (b *byteBuffer) ReadShortByteArray() ([]byte, error) {
if b.RemainingReaderBytes() < 2 {
return nil, ErrOutOfBounds.CreateEmpty()
+1 -1
View File
@@ -1,4 +1,4 @@
package universe_io
package uio
import (
"universe.mrlokop.dev/core/errors"
+37 -1
View File
@@ -1,9 +1,45 @@
package universe_io
package uio
type Sink interface {
Write(src []byte) (n int, err error)
WriteFully(src []byte) error
}
type BufferedSink interface {
Sink
WriteByte(b byte) error
WriteUByte(b uint8) error
WriteShortLE(v int16) error
WriteShortBE(v int16) error
WriteIntLE(v int32) error
WriteIntBE(v int32) error
WriteLongLE(v int64) error
WriteLongBE(v int64) error
WriteUShortLE(v uint16) error
WriteUShortBE(v uint16) error
WriteUIntLE(v uint32) error
WriteUIntBE(v uint32) error
WriteULongLE(v uint64) error
WriteULongBE(v uint64) error
WriteFloatLE(v float32) error
WriteFloatBE(v float32) error
WriteDoubleLE(v float64) error
WriteDoubleBE(v float64) error
// WriteShortByteArray writes a size-prefixed byte array.
// Structure: [ShortLE : size][size bytes data]
WriteShortByteArray(data []byte) error
// WriteByteArray writes a size-prefixed byte array.
// Structure: [IntLE : size][size bytes data]
WriteByteArray(data []byte) error
WriteShortString(s string) error
WriteString(s string) error
}
+2 -1
View File
@@ -1,7 +1,8 @@
package universe_io
package uio
type Source interface {
Read(dst []byte) (n int, err error)
ReadFully(dst []byte) error
}
type BufferedSource interface {
+1 -1
View File
@@ -1,3 +1,3 @@
package universe_io
package uio
type Cursor uint