Trying to generify «case class codecs»

message types and quality of service are represented as case classes. Each
one has its own encoding to unsigned integers. But in each case the
algorithm is obviously the same. My point here is to abstract the algorithm
out. My solution works but I'm not completely satisfied!