简体   繁体   English

如何使用cbor2序列化和反序列化对象?

[英]How to serialize and deserialize objects with cbor2?

I'm trying to serialize and deserialize object using cbor2 but even after following the documentation I cannot properly do it. 我正在尝试使用cbor2序列化和反序列化对象,但是即使按照文档进行操作,我也无法正确执行。 Let' suppose I have the following two classes: 假设我有以下两个类:

class A(object):
    def __init__(self):
        self.a = 5
        self.b = set()

    def a(self):
        return self.a

class B(object):
    def __init__(self, a):
        self._a = a

    def a(self):
        return a

a = A()
b = B(a)

Can anyone show me how to do it for the object a please? 谁能告诉我如何做到这一点的对象a好吗?

Thanks 谢谢

Sorry for a late answer. 对不起,我来不及回答。

CBOR2 is currently missing support for serializing sets which could be stored as tagged arrays. CBOR2当前缺少对序列集的支持,序列集可以存储为标记数组。

There is a ticket for adding support here: 这里有添加支持的票证:

https://github.com/agronholm/cbor2/issues/14 https://github.com/agronholm/cbor2/issues/14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM