This is a created article in which the information may have evolved or changed.
Package Mainimport ("bytes" "Encoding/binary" "FMT") type Register struct {ACTION int32sid int32}func examplewrite () []byte {buf: = new (bytes. Buffer) var info registerinfo.action = 20004info. SID = 6err: = binary. Write (buf, Binary. Littleendian, info) if err! = Nil {fmt. Println ("Binary. Write failed: ", err)}fmt. Printf ("% x\n", buf. Bytes ()) return BUF. Bytes ()}func exampleread (b []byte) {var info registerbuf: = Bytes. Newbuffer (b) Err: = Binary. Read (buf, Binary. Littleendian, &info) if err! = Nil {fmt. Println ("Binary. Read failed: ", err)}fmt. Print (Info)//Output:3.141592653589793}func main () {buf: = Examplewrite () exampleread (BUF)}
The Go Language standard library provides JSON,GOB and BASE32,BASE64 serialization in addition to binary
For serialization of the Protocol Buff Protocol, refer to Goprotobuf