Pystruct is a module like python struct module
> go get github.com/WesleiRamos/pystruct
Pack
returns byte array
Unpack
returns interface array
NOTICE: Tested only with small values
package main
import "fmt"
import "reflect"
import "github.com/WesleiRamos/pystruct"
func main() {
h := "kk eae man"
b := pystruct.Pack("!hs", len(h), h)
fmt.Printf("%q\n", b) // "\x00\nkk eae man"
u, err := pystruct.Unpack("!h", b[:2])
if err != nil {
panic(err)
}
fmt.Printf("%s\n", b[2:2+reflect.ValueOf(u[0]).Int()]) // kk eae man
}