> I am trying to read registers from a file, but os.Read() require a []
> byte parameter, and my data structure is similar to:
> type Data struct {
> id uint64;
> name [100]byte;
> telephone [100]byte;
> }
>
> How can I cast []byte to Data?
You can't, mainly because it breaks the type system (what if one
of the struct fields were a pointer?) but also because it produces
non-portable code.
http://golang.org/pkg/encoding/binary/ will read binary data into
a struct as long as you tell it the endianness and the struct uses
only basic types like you have above.
You'd say
var myData Data;
binary.Read(os.Stdin, binary.LittleEndian, &myData);
Russ