I'm testing about serialization with bytes or slices, just learning and trying. I would like to bind 3 parameters in a single 10 bytes field, but I don't now how to concatenate them in Crystal or whether it is possible. I know I can achieve this by creating arrays or tuples, but I want to try whether it is possible to mix the parameters into a single buffer.
For instance, I want a self-descriptive binary record ID mixing 3 parameters:
Type (UInt8) | Category (UInt8) | Microseconds (UInt64) = Total 80 bits - 10 bytes
type = 1_u8 # 1 byte
categ = 4_u8 # 1 byte
usec = 1527987703211000_u64 # 8 bytes (Epoch)
How do I concatenate all this variables into a continuous 10 bytes buffer?
I want to retrieve the data by the index, like:
type = buff[0,1]
categ = buff[1,1]
usec = buff[2,8].to_u64 # (Actually not possible)