I came up with this solution (via the encoding/binary package) that works
fine, but seems kinda complicated when compared to what I'd have to do in
C. I'm new to Go and I want to know if there is a better way of doing the
same. Any suggestions/ideas on improving this?
type array_entity_t struct {
Id uint8
Sn [256]byte
}
type array_save_t struct {
Count uint8
Array [64]array_entity_t
Checksum uint8
}
func main() {
var err error
save := new(array_save_t)
totalSize := (unsafe.Sizeof(*save))
chars := make([]byte, totalSize)
fi, err := syscall.Open(HCA, syscall.O_RDONLY, 0)
if err != nil {
panic(err)
}
defer syscall.Close(fi)
_, errno := syscall.Read(fi, chars)
if err = os.NewSyscallError("SYS_READ", errno); err != nil {
panic(err)
}
reader := strings.NewReader(string(chars[0:]))
if err = binary.Read(reader, binary.LittleEndian, save); err != nil {
panic(err)
}
// blah
}
Thank you!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.