How to use the cbor2.CBORTag function in cbor2

To help you get started, we’ve selected a few cbor2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github piwheels / piwheels / tests / test_transport.py View on Github external
def test_decoding_unknown_type():
    ctx = Context()
    pull = ctx.socket(PULL)
    push = ctx.socket(PUSH)
    pull.bind('inproc://foo')
    push.connect('inproc://foo')
    push.send(cbor2.dumps(cbor2.CBORTag(4000, None)))
    with pytest.raises(IOError):
        pull.recv_msg()
    push.close()
    pull.close()
github piwheels / piwheels / piwheels / transport.py View on Github external
def default_encoder(encoder, value):
    if isinstance(value, dt.timedelta):
        encoder.encode(
            cbor2.CBORTag(2001, (
                value.days, value.seconds, value.microseconds)))
    elif value is NoData:
        encoder.encode(cbor2.CBORTag(2002, None))
    else:
        raise cbor2.CBOREncodeError(
            'cannot serialize type %s' % value.__class__.__name__)
github rokups / Launchpad / src / common / encoder.py View on Github external
def cbor2_encoder(encoder, value):
    """
    Converts objects of various types to cbor-compatible types.
    :param encoder: cbor encoder that should be called
    :param value: value to encode
    """

    if isinstance(value, Exception):
        encoder.encode(CBORTag(_Tags.EXCEPTION.value, encoder.encode_to_bytes({
            'type': type(value).__name__,
            'dict': value.__dict__
        })))
    else:
        raise ValueError('Encoding of type {} is not supported'.format(type(value).__name__))
github piwheels / piwheels / piwheels / transport.py View on Github external
def default_encoder(encoder, value):
    if isinstance(value, dt.timedelta):
        encoder.encode(
            cbor2.CBORTag(2001, (
                value.days, value.seconds, value.microseconds)))
    elif value is NoData:
        encoder.encode(cbor2.CBORTag(2002, None))
    else:
        raise cbor2.CBOREncodeError(
            'cannot serialize type %s' % value.__class__.__name__)