cstruct

package module
v0.0.0-...-f4db460 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

cstruct

Go package implementing cstruct-style pack/unpack

API Reference

// LittleEndian byte order (i.e. least signficant byte first) for {|u}int{16|32|64} types
var LittleEndian = binary.LittleEndian

// BigEndian byte order (i.e. most signficant byte first) for {|u}int{16|32|64} types
var BigEndian = binary.BigEndian

// Examine may be used to determine the size of a []byte needed by Pack()
func Examine(objIF interface{}) (bytesNeeded uint64, trailingByteSlice bool, err error)

// Pack is used to serialize the supplied struct (passed by value or reference) in the desired byte order
func Pack(srcObjIF interface{}, byteOrder binary.ByteOrder) (dst []byte, err error)

// Unpack is used to deserialize into the supplied struct (passed by reference) in the desired byte order
//
// Note that if the supplied struct contains a trailing byte slice, bytesConsumed will equal len(src)
func Unpack(src []byte, dstObjIF interface{}, byteOrder binary.ByteOrder) (bytesConsumed uint64, err error)

Contributors

License

See the included LICENSE file

Documentation

Overview

Package cstruct supports the serialization/deserialization of Go structs

Supported Go struct field types are:

bool - stored as 1 Byte value with 0x01 indicating true and 0x00 indicating false
int8
uint8 - equivalent to byte
int16
uint16
int32
uint32
int64
uint64
[<n>]<type> - a counted array of <type>
struct - an embedded struct
[]byte - a trailing arbitrarily long slice of bytes

Index

Constants

This section is empty.

Variables

View Source
var BigEndian = binary.BigEndian

BigEndian byte order (i.e. most signficant byte first) for {|u}int{16|32|64} types

View Source
var LittleEndian = binary.LittleEndian

LittleEndian byte order (i.e. least signficant byte first) for {|u}int{16|32|64} types

Functions

func Examine

func Examine(objIF interface{}) (bytesNeeded uint64, trailingByteSlice bool, err error)

Examine may be used to determine the size of a []byte needed by Pack()

func Pack

func Pack(srcObjIF interface{}, byteOrder binary.ByteOrder) (dst []byte, err error)

Pack is used to serialize the supplied struct (passed by value or reference) in the desired byte order

func Unpack

func Unpack(src []byte, dstObjIF interface{}, byteOrder binary.ByteOrder) (bytesConsumed uint64, err error)

Unpack is used to deserialize into the supplied struct (passed by reference) in the desired byte order

Note that if the supplied struct contains a trailing byte slice, bytesConsumed will equal len(src)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL