chore: Update

This commit is contained in:
Artёm Mishin committed 2025-05-26 04:34:59 +03:00
1 parent de051ef362
commit 0218c2131f
2 files changed
+83

No files matched your search

+48
View File
@@ -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()