en Home Smtp Sometimes I fall in love with code jgdb A Gopher named Gophy Encode/Decode Golang data to Gob files GoWatch Cfg File Access and Create Time Go Snippets Ping Citadel vCard Sync Your Everyday Go Tools Cases Conv Go jkl Crypt HDKeys Wordlist HDKeys Recover

Encode/Decode between struct and byte slice

This is handy if you need to send a struct to a database or network

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


First Created: 2015-01-28T19:54:59Z
Last Modified: 2026-04-05 19:35