Skip to content

Conversation

@foxxorcat
Copy link

This is a very good library, but it may not meet the requirements when handling certain data.

// uint24
type Address uint32

func (a Address) Serialize(w io.Writer, order binarystruct.ByteOrder) (int, error) {
	var buf [4]byte
	binary.BigEndian.PutUint32(buf[:], uint32(a)&0xffffff)
	return w.Write(buf[1:])
}

func (a *Address) Deserialize(r io.Reader, order binarystruct.ByteOrder) (n int, err error) {
	var buf [4]byte
	n, err = r.Read(buf[1:])
	if err == nil {
		*a = Address(binary.BigEndian.Uint32(buf[:]) & 0xffffff)
	}
	return
}

var _ binarystruct.Serializer = (*Address)(nil)
var _ binarystruct.Deserializer = (*Address)(nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant