Skip to content

Commit

Permalink
Merge pull request #6 from denis-sumin/fix-bytes
Browse files Browse the repository at this point in the history
Fix bytes protobuf type
  • Loading branch information
Riku Ayanokozy authored Nov 22, 2016
2 parents 3e42f85 + 8465fcd commit f7f5df4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/protobuf_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
FieldDescriptor.TYPE_SFIXED64: int if six.PY3 else six.integer_types[1],
FieldDescriptor.TYPE_BOOL: bool,
FieldDescriptor.TYPE_STRING: six.text_type,
FieldDescriptor.TYPE_BYTES: lambda b: base64.b64encode(b),
FieldDescriptor.TYPE_BYTES: six.binary_type,
FieldDescriptor.TYPE_ENUM: int,
}

Expand Down Expand Up @@ -115,12 +115,7 @@ def _get_field_value_adaptor(pb, field, type_callable_map=TYPE_CALLABLE_MAP, use
pb.__class__.__name__, field.name, field.type))


def get_bytes(value):
return base64.b64decode(value)


REVERSE_TYPE_CALLABLE_MAP = {
FieldDescriptor.TYPE_BYTES: get_bytes,
}


Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_proto_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,5 @@ def compare(self, m, d, exclude=None):
assert field.name in d, field.name
assert d[field.name] == getattr(m, field.name), (field.name, d[field.name])
assert i > 0
assert m.byts == base64.b64decode(d['byts'])
assert m.byts == d['byts']
assert d['nested'] == {'req': m.nested.req}

0 comments on commit f7f5df4

Please sign in to comment.