Documentation ¶
Overview ¶
Package serial provides helper function for serializing data.
Index ¶
- Constants
- func MarshalBoolSlice(bls []bool, b []byte)
- func MarshalByteSlices(prefixLens []int, data [][]byte) ([]byte, error)
- func MarshalUint16(ui uint16, b []byte) []byte
- func MarshalUint32(ui uint32, b []byte) []byte
- func UnmarshalBoolSlice(b []byte) []bool
- func UnmarshalByteSlices(prefixLens []int, b []byte) ([][]byte, error)
- func UnmarshalUint16(b []byte) uint16
- func UnmarshalUint32(b []byte) uint32
- type ByteSlicesPrefixer
- type SlicesPacker
Constants ¶
const ( // ErrLengthsDoNotMatch is returned when a ByteSlicesPrefixer is given data // with the wrong number of byte slices. ErrLengthsDoNotMatch = errors.String("Lengths do not match") // ErrLengthTooLong is returned if a ByteSlicesPrefixer length is above 8. ErrLengthTooLong = errors.String("Length cannot exceed 8 bytes") // ErrIncorrectZero is returned when a BySlicesPrefixer has a zero in any but // the last position. ErrIncorrectZero = errors.String("Zero is only valid as final length") // ErrBadFormat is returned during ByteSlicesPrefixer Unmarshal if the format // does not match the description. ErrBadFormat = errors.String("Not properly formatted") )
Variables ¶
This section is empty.
Functions ¶
func MarshalBoolSlice ¶
MarshalBoolSlice marshals a slice of bools into a byte slice. Each bool takes only one bit. It does not check the slice length and will panic if the slice is not long enough. The required length with be the length of the bool slice divided by 8 rounded up plus 4.
func MarshalByteSlices ¶
MarshalByteSlices takes a slice of byte slices and marshals them into a a single byte slice. The prefixLens determine how many bytes to use for length headers. Positive values set the length in bytes, values less than or equal to 0 will result in no prefix being added.
func MarshalUint16 ¶
MarshalUint16 takes a unit and a byte slice and writes the uint16 to the first 2 bytes of the slice. It does not check the slice length and will panic if the slice does not have a length of at least 2.
func MarshalUint32 ¶
MarshalUint32 takes a unit and a byte slice and writes the uint32 to the first 4 bytes of the slice. It does not check the slice length and will panic if the slice does not have a length of at least 4.
func UnmarshalBoolSlice ¶
UnmarshalBoolSlice will unmarshal a slice of bools from a byte slice. If the byte slice is malformed, it may panic.
func UnmarshalByteSlices ¶
UnmarshalByteSlices takes a byte slice and breaks it into a slice of byte slices. The prefixes determine what length headers to expect. Postive values are interpreted as the number of bytes to read as the length header. Negative values indicate the absolute length (so -5 means the slice is 5 bytes long) and 0 is only valid for the final value and means consume the rest.
func UnmarshalUint16 ¶
UnmarshalUint16 reads the first 2 bytes of a slice into a uint16. It does not check the slice length and will panic if the slice does not have a length of at least 2.
func UnmarshalUint32 ¶
UnmarshalUint32 reads the first 4 bytes of a slice into a uint32. It does not check the slice length and will panic if the slice does not have a length of at least 4.
Types ¶
type ByteSlicesPrefixer ¶
type ByteSlicesPrefixer []int
ByteSlicesPrefixer describes how to prefix a [][]byte for serialization.
type SlicesPacker ¶
SlicesPacker describes the number of bytes to use to describe the count of slices and Size describes the number of bytes to use to describe the size of each slice