synodriver / sproto

pythonic sproto binding

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

✨ Pysproto ✨

Another Pythonic Sproto Python binding for sproto

Powered by cython, high performance, pythonic

pypi python implementation wheel license action

Usage

  • install
pip install sproto
  • encode & decode
from pysproto import parse, parse_ast, Sproto
ast = parse(""".package {
                    type 0 : integer
                    session 1 : integer
                    }""")
dump = parse_ast(ast)
proto = Sproto(dump)
tp = proto.querytype("package")
encoded = tp.encode({"type": 1, "session": 2})
print(tp.decode(encoded))
  • Public functions
from typing import Union, Tuple, Optional

class Sproto:
    def dump(self)->None: ...
    def protocol(self, tag_or_name: Union[int, str]) -> Tuple[Union[int, str], Optional["SprotoType"], Optional["SprotoType"]]: ...
    def querytype(self, type_name) -> "SprotoType": ...
    def sproto_protoresponse(self, intproto) -> int: ...

class SprotoError(Exception): ...

class SprotoType:
    @classmethod
    def __init__(self, *args, **kwargs) -> None: ...
    def decode(self, buffer: bytes) -> dict: ...
    def encode(self, data: dict) -> bytes: ...
    def encode_into(self, data: dict, buffer: bytearray) -> int: ...

def pack(data: bytes) -> bytes: ...
def pack_into(data: bytes, buffer: bytearray) -> int: ...
def unpack(data: bytes) -> bytes: ...
def unpack_into(data: bytes, buffer: bytearray) -> int: ...
  • xx_into functions accepts buffer protocol objects, which is zerocopy.

About

pythonic sproto binding

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 52.7%Language:Cython 47.3%