/go-binary-pack

Golang implementation of Python's struct package

Primary LanguageGoBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Go BinaryPack

Build Status GoDoc

BinaryPack is a simple Golang library which implements some functionality of Python's struct package.

Install

go get github.com/roman-kachanovsky/go-binary-pack/binary-pack

How to use

// Prepare format (slice of strings)
format := []string{"I", "?", "d", "6s"}

// Prepare values to pack
values := []interface{}{4, true, 3.14, "Golang"}

// Create BinaryPack object
bp := new(BinaryPack)

// Pack values to []byte
data, err := bp.Pack(format, values)

// Unpack binary data to []interface{}
unpacked_values, err := bp.UnPack(format, data)

// You can calculate size of expected binary data by format
size, err := bp.CalcSize(format)