Unify protobuf encoding logic.
Unify protobuf decoding logic.