Skip to content

Support encoding/decoding bytes to/from hex strings #964

@iliastsa

Description

@iliastsa

Description

It would be great if we decode hex strings to bytes (and similarly encode to them). For example:

def main():
    t = MyClass(data=b"abc")

    # Somehow configure the Struct field that it's a hex encoded byte string.
    # Right, the input expects a base64 encoded byte string.
    tt = decode(b'{"data":"0x616263"}', type=MyClass)

    assert t == tt

if __name__ == "__main__":
    main()

I know this is doable using a dec_hook/enc_hook, but at my job we are decoding a huge number of such fields and it's taking a non-trivial time of our data decoding -- moving this logic directly in the msgpsec library should provide a significant boost in performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions