lunixbochs / struc

Better binary packing for Go
MIT License
572 stars 45 forks source link

struc.Float16 does not work with slices #66

Open curio77 opened 5 years ago

curio77 commented 5 years ago

If I have a format definition like this:

type format struct {
    Field struc.Float16 `struc:"float16,little"`
    Fields [42]struc.Float16 `struc:"[42]float16,little"`
}

then upon unpacking (haven't checked if it affects packing as well), Field will parse two bytes (as expected), but Fields will wrongly try to parse 42 × 8 bytes (the size of float64 which struc.Float16 equates to) instead of 42 × 2.

lunixbochs commented 5 years ago

Can you try with this PR? https://github.com/lunixbochs/struc/pull/63

curio77 commented 5 years ago

That gives me a panic: array/slice of custom struct is not supported: [42]struc.Float16.

13rac1 commented 5 years ago

@curio77 That's by design. The logic is: A panic is a better than working wrong. See #65

andig commented 4 years ago

To summarize: #63 does fix the broken behavior by explicit panic which is good. Op‘s original issue of slice of struct not supported remains.

andig commented 4 years ago

@lunixbochs wouldn‘t it make sense to merge #63? @13rac1 are you maintaining a fork intendend for public usage?