Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading < 8 bits from a reader in Golang

Tags:

While handling raw IP packages in Golang I've came across a problem which I cannot seem to find a solution for:

The IPv4 specification contains fields which are smaller than 8 bits. For example the Version or the Header Length (4 bits each) or the Flags (3 bits).

How do I read those values from an io.Reader and handle them using Golang afterwards? I've been using the binary.Read method so far, however since the smallest integer type in Golang is an int8, that is not possible in this case.