dlin
unread,Jun 17, 2011, 10:00:38 PM6/17/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
I'm trying to write a convert file format sample.
There some questions in this process stopped me.
1. How to convert struct into byte string?
2. How to save struct into file in a simple line (maybe by io/ioutil)?
3. Is there simpler Go syntax to declare initial array value?
func genSample(fName string) {
h := Header_v1_t{Version:1, BlockCnt:3}
b1s := []B1_v1_t{ B1_v1_t{1, 2, 3}, B1_v1_t{1, 4, 5}, B1_v1_t{1, 6,
7}}
b2s := []B2_v1_t{
B2_v1_t{2, 4, 5, [2]uint16{6,7}, [8]byte{8,9,10,11,12,13,14,15}},
B2_v1_t{2, 6, 7, [2]uint16{8,9}, [8]byte{9,10,11,12,13,14,15,16}},
B2_v1_t{2, 8, 9, [2]uint16{1,2}, [8]byte{10,11,12,13,14,15,16,17}}}
d := []byte(h) // FIXME: compile failed
fmt.Printf("%#v\n%#v\n%#v\n%#v", h, b1s, b2s, d)
}
type Header_v1_t struct {
Version uint16 //= 1
BlockCnt uint8
}
type B1_v1_t struct {
Tag uint8 // = 1
A uint16
B uint32
}
type B2_v1_t struct {
Tag uint8 // = 2
E uint16
F uint8
G [2]uint16
H [8]byte
}