aim-oscar-server/oscar/buf.go
2021-12-17 19:01:22 -05:00

49 lines
913 B
Go

package oscar
import (
"aim-oscar/util"
"encoding"
"encoding/binary"
)
type Buffer struct {
d []byte
}
func (b *Buffer) WriteUint8(x uint8) {
b.d = append(b.d, x)
}
func (b *Buffer) WriteUint16(x uint16) {
b.d = append(b.d, 0, 0)
binary.BigEndian.PutUint16(b.d[len(b.d)-2:], x)
}
func (b *Buffer) WriteUint32(x uint32) {
b.d = append(b.d, 0, 0, 0, 0)
binary.BigEndian.PutUint32(b.d[len(b.d)-4:], x)
}
func (b *Buffer) WriteUint64(x uint64) {
b.d = append(b.d, 0, 0, 0, 0, 0, 0, 0, 0)
binary.BigEndian.PutUint64(b.d[len(b.d)-8:], x)
}
func (b *Buffer) WriteString(x string) {
b.d = append(b.d, []byte(x)...)
}
func (b *Buffer) Write(x []byte) (int, error) {
b.d = append(b.d, x...)
return len(x), nil
}
func (b *Buffer) WriteBinary(e encoding.BinaryMarshaler) {
d, err := e.MarshalBinary()
util.PanicIfError(err)
b.d = append(b.d, d...)
}
func (b *Buffer) Bytes() []byte {
return b.d
}