Documentation ¶
Overview ¶
Package binary_pack performs conversions between some Go values represented as byte slices. This can be used in handling binary data stored in files or from network connections, among other sources. It uses format slices of strings as compact descriptions of the layout of the Go structs.
Format characters (some characters like H have been reserved for future implementation of unsigned numbers):
? - bool, packed size 1 byte b - int8, packed size 1 bytes B - uint8, packed size 1 bytes h - int16, packed size 2 bytes H - uint16, packed size 2 bytes i, l - int32, packed size 4 bytes I, L - int32, packed size 4 bytes q - int64, packed size 8 bytes Q - uint64, packed size 8 bytes f - float32, packed size 4 bytes d - float64, packed size 8 bytes Ns - string, packed size N bytes, N is a number of runes to pack/unpack
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryPack ¶
type BinaryPack struct{}
BinaryPack presents a BinaryPack
func (*BinaryPack) CalcSize ¶
func (bp *BinaryPack) CalcSize(format []string) (int, error)
CalcSize Returns the size of the struct (and hence of the byte slice) corresponding to the given format.
func (*BinaryPack) Pack ¶
func (bp *BinaryPack) Pack(format []string, msg []interface{}) ([]byte, error)
Pack returns a byte slice containing the values of msg slice packed according to the given format. The items of msg slice must match the values required by the format exactly.
func (*BinaryPack) UnPack ¶
func (bp *BinaryPack) UnPack(format []string, msg []byte) ([]interface{}, error)
UnPack the byte slice (presumably packed by Pack(format, msg)) according to the given format. The result is a []interface{} slice even if it contains exactly one item. The byte slice must contain not less the amount of data required by the format (len(msg) must more or equal CalcSize(format)).