I think having friend Input/Output classes to ByteArray, as you suggested, would help make this easier.