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 :
Advertisement
Something interesting
Tutorials
+9.4k Golang : Apply Histogram Equalization to color images
+11.5k CodeIgniter : Import Linkedin data
+5k Golang : micron to centimeter example
+8.3k Golang : Auto-generate reply email with text/template package
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+17.9k Golang : Login and logout a user after password verification and redirect example
+11.1k Golang : Read until certain character to break for loop
+18.5k Golang : Write file with io.WriteString
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+15.4k Golang : Find location by IP address and display with Google Map
+7.8k Golang : Reverse a string with unicode
+48.1k Golang : How to convert JSON string to map and slice