Giter VIP home page Giter VIP logo

Comments (4)

prusnak avatar prusnak commented on July 30, 2024

We are using a patched version of protobuf_json that uses hexlify instead of encode('string_escape') for serializing bytes.

I don't think we'll do the unbundling unless:
a) protobuf_json is published to PyPI
b) it allows easy configuration of callbacks hardcoded in _ftype2js and _js2ftype: https://github.com/dpp-name/protobuf-json/blob/master/protobuf_json.py#L109-L147

from python-trezor.

hegjon avatar hegjon commented on July 30, 2024

Thanks for your feedback, I included this ticket as a comment in the RPM package for Fedora

from python-trezor.

prusnak avatar prusnak commented on July 30, 2024

At least I tried to minimize the diff between upstream protobuf_json.py and our version in 725b64b

so the difference is now just the following:

--- protobuf_json.py
+++ protobuf_json.py
@@ -92,6 +92,10 @@ def pb2json(pb, useFieldNumber=False):
             key = field.name
         if field.type == FD.TYPE_MESSAGE:
             ftype = partial(pb2json, useFieldNumber=useFieldNumber)
+        # ---- monkey patching ----
+        elif field.type == FD.TYPE_ENUM:
+            ftype = lambda x: field.enum_type.values[x].name
+        # ---- end of monkey patching ----
         elif field.type in _ftype2js:
             ftype = _ftype2js[field.type]
         else:
@@ -146,3 +150,13 @@ _js2ftype = {
     FD.TYPE_SINT64: long,
 }
 
+# more monkey patching
+
+import binascii
+from . import types_pb2 as types
+
+_ftype2js[FD.TYPE_BYTES] = lambda x: binascii.hexlify(x)
+del _ftype2js[FD.TYPE_ENUM] # handled specially
+
+_js2ftype[FD.TYPE_BYTES] = lambda x: binascii.unhexlify(x)
+_js2ftype[FD.TYPE_ENUM] = lambda x: getattr(types, x)

from python-trezor.

hegjon avatar hegjon commented on July 30, 2024

Thanks, the python-trezor RPM package for Fedora just got approved

from python-trezor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.