I want to serialise some data in Go and I have to write the individual bits. (Specifically for Huffman encoding). What is the best way to do this? The most obvious way would be to just take eight bits at a time and shift the first one 7 places to the left, six with the next one and so on.
I was wondering whether or not there was a more idiomatic way to do this, possibly a function in the standard library. I've had a look at encoding/gob, however it does not seem to offer the control I wish, for example writing a slice of 4 booleans (which I would have thought corresponded to bits) outputed 24 bytes. I'm guessing it has numbers which signify slice start, boolean next etc.
Is there a good way to do this?