Golang encoding/binary.Read() function example

package encoding/binary

Read reads structured binary data from r (1st parameter) into data(3rd parameter). Data must be a pointer to a fixed-size value or a slice of fixed-size values. Bytes read from r are decoded using the specified byte order(2nd parameter) and written to successive fields of the data. When reading into structs, the field data for fields with blank (_) field names is skipped; i.e., blank field names may be used for padding. When reading into a struct, all non-blank fields must be exported.

Golang encoding/binary.Read() function usage example

 var seg32 Segment32
 var cmddat []byte
 b := bytes.NewReader(cmddat)
 if err := binary.Read(b, binary.BigEndian, &seg32); err != nil {
 fmt.Println(err)
 }

Reference :

http://golang.org/pkg/encoding/binary/#Read

Advertisement