Giter Site home page Giter Site logo

pyproto's Introduction

Install

pip install python-protobuf

Example

from pyproto import Protobuf

print("Test the conversion between protobuf and bytes")
bs = bytes.fromhex("12001a0022020801") # A section of bytes data of protobuf
print("src:", bs.hex())
proto = ProtoBuf(bs)  # Convert bytes to protobuf objects
proto.dump()  # print proto object
bs2 = proto.toBuf()  # Convert the proto object to bytes
print(bs2 == bs, bs2.hex())

print("Mutual conversion between proto object and dict object")
# A complex 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}},
    }
}

# An unassigned dict object template

d2 = {6: {1: {1: ""}, 3: "", 4: {1: 0}, 5: {1: 0}, 6: {2: "", 3: "", 4: {1: 0}}}}
print("src:", d)
pb = ProtoBuf(d)  # Convert dict object to protobuf object

pb.dump()

d3 = pb.toDict(d2)  # Convert protobuf object to dict object

print("d3 == d2 ->", d3 == d2, d3 is d2, d3)
print("d3 == d  ->", d3 == d, d3 is d)

pyproto's People

Contributors

grayrail000 avatar xtekky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyproto's Issues

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.