Install
pip install python-protobuf
Example
from pyproto import Protobuf
print("Test the conversion between protobuf and bytes")
bs = bytes.fromhex("12001a0022020801")
print("src:", bs.hex())
proto = ProtoBuf(bs)
proto.dump()
bs2 = proto.toBuf()
print(bs2 == bs, bs2.hex())
print("Mutual conversion between proto object and dict object")
d = {
6: {
1: {
1: "eyJhbGciOiJIUzI1NiJ9.ODYxODAyNjMyNjcwMA.KGj7v_WjlntNODpPNe4fVbJA5sPhLjZbQidBLhcrGVM"
},
3: "5******7@*****.com",
4: {1: 6},
5: {1: 1},
6: {2: "", 3: "", 4: {1: 1}},
}
}
d2 = {6: {1: {1: ""}, 3: "", 4: {1: 0}, 5: {1: 0}, 6: {2: "", 3: "", 4: {1: 0}}}}
print("src:", d)
pb = ProtoBuf(d)
pb.dump()
d3 = pb.toDict(d2)
print("d3 == d2 ->", d3 == d2, d3 is d2, d3)
print("d3 == d ->", d3 == d, d3 is d)