On Tue, 21 Apr 2020 02:22:37 -0700 (PDT)
Rakesh K R <
rakesh...@gmail.com> wrote:
> In C, we used to typecast this array of uint8_t to predefined
> structure.
>
This is very bad even for a C program, as soon as you dereference
pointer to such structure it's an undefined behavior, and not portable
even on LE architectures, definitely such dereference would lead to a
runtime crash on arm cpus, ubuntu or docker wouldn't change anything,
also, the c compiler might add padding to your structure, which can
make such parser give the wrong answer even on architectures that allows
unaligned addressing. (unless you're non-standard compiler extensions
to avoid that)
Thus, even on C, the correct and portable way to parse an uint8_t array
is also going bytes one by one, i recommend you stick with the
"encoding/binary" package, it will do the right thing.
BR.
—wagner