Except using cgo, Do you know what is the best way to pack the GO object to byte slice?
We can use encoding/binary package to serialize GO struct to byte slice as far as we know but it supports only fixed-length variable so cannot support following case.
typedef struct
{
uint32_t foo:12;
uint32_t bar:9;
uint32_t baz:1;
uint32_t qux:10;
} type_t;
Do we need to implement GO struct with getter/setter for this case with terrible bit manipualtion considering endianness? Such as:
type typeT struct
{
fooBarBazQux uint32
}
// some complex bit manipulation considering endianness
func (t typeT) getFoo() uint32 {
}
func (t typeT) setFoo(val uint32) {
}
Is there any better solution for this?
I tried encoding/json mashaler for my custom type but encoding/binary package does not seem to support this kind of interface.
I need your help.