add encode for protobuf