Closed ayh20 closed 3 years ago
I think this doesn't work because []Zone in the struct tag doesn't make any sense to the parser. At that level, struc doesn't know about the Zone type - the string type names it can parse from the tag are a fixed list.
https://github.com/lunixbochs/struc/blob/master/struc_test.go#L26
The ways to work around this are probably:
Ryan, Thanks so much for the response. You are absolutely correct and I've got myself all mixed up (I blame coding in 4 different languages at the same time).
The solution (as it's fixed length) is simply:
type InputData {
ZoneData [25]Zone `struc:"[25]Zone"`
}
I don't think you need the struc tag on that
I've been using your great library for a while and have come across a scenario that feels like it should work but doesn't. I currently have this scenario in a struct and it work nicely:
Where Zone is:
But i now need to be able to do this with a fixed number of zones where i don't have a field to use as a sizefrom
Logically the above sounds like the solution and some of your examples show the use of [] in the struc definition.
running the above example throws "struc: field
Zone
is a slice with no length or sizeof field." So the error seems to imply that I should be able to pass a fixed length. Looking at the code i can't see anywhere that the length it used.Should it work this way ? can you specify a fixed size for my array ?