first commit

This commit is contained in:
2022-12-24 17:48:08 +02:00
commit 57c4f8e7b9
6 changed files with 2513 additions and 0 deletions

47
buffer.go Normal file
View File

@@ -0,0 +1,47 @@
package bin
type Buffer struct {
arr []byte
}
func NewBuffer(arr []byte) *Buffer {
s := new(Buffer)
s.arr = arr
return s
}
func (s *Buffer) WriteByte(b byte) (err error) {
s.arr = append(s.arr, b)
return nil
}
func (s *Buffer) Write(data []byte) (int, error) {
s.arr = append(s.arr, data...)
return len(data), nil
}
func (s *Buffer) ByteAt(idx int) byte {
return s.arr[idx]
}
func (s *Buffer) WriteByteAt(b byte, idx int) {
s.arr[idx] = b
}
func (s *Buffer) Len() int {
return len(s.arr)
}
func (s *Buffer) Bytes() []byte {
return s.arr[:]
}
func (s *Buffer) CopyBytes() []byte {
dst := make([]byte, len(s.arr))
copy(dst, s.arr)
return dst
}
func (s *Buffer) Reset() {
s.arr = s.arr[:0]
}