gob

Encode/Decode between struct and byte slice

sbs stands for Struct to Byte Slice and back to Struct Internals: sbs encodes your struct first to a Gob, then it convers it to a byte slice; it reverses the process for decoding. Example type Foo struct { A int B string } p := &Foo{111,"A string"} byteslice, err := sbs.Enc(p) ... foo := new(Foo) structobject, err := sbs.Dec(foo, byteslice) ... Code is available at https://bitbucket.org/gotamer/sbs

Encode/Decode Golang data to Gob files

Golang has a package called Gob to encode and decode values in to go specific binary format for transmiting as streams or for saving to file. Below are two functions, Load and Save to encode/decode go values including struct’s in to files. package main import ( "encoding/gob" "fmt" "os" "runtime" ) const file = "/tmp/test.gob" type User struct { Name, Pass string } func main(){ var datato = &User{"Donald","DuckPass"} var datafrom = new(User) err := Save(file, datato) Check(err) err = Load(file, datafrom) Check(err) fmt.