I'm thinking of such API, however, I'm struggling to implement it. I can't think on how I can implement the decode and the primitive decoders (dec_int8, dec_int16, dec_int32). The return of decode is supposed to be a Result(#(Foo, BitArray), DecodeError) where the 2nd element of the tuple is the remaining BitArray after applying the decoders. It's not so easy to list/explain what I tried and I hope that it's okay not to list them to ask your opinions on how to implement it.
PS: I do have already a way for the decoding but I'm finding the listed API here to be elegant. Much like what lpil did recently in the dynamic module.