Skip to main content

sproto encode and decode

Project description

✨ 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sproto-0.1.2.tar.gz (209.0 kB view hashes)

Uploaded Source

Built Distributions

sproto-0.1.2-cp312-cp312-win_amd64.whl (275.7 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

sproto-0.1.2-cp312-cp312-manylinux2014_x86_64.whl (314.8 kB view hashes)

Uploaded CPython 3.12

sproto-0.1.2-cp312-cp312-macosx_10_9_x86_64.whl (380.7 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

sproto-0.1.2-cp312-cp312-macosx_10_9_arm64.whl (377.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ ARM64

sproto-0.1.2-cp311-cp311-win_amd64.whl (275.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

sproto-0.1.2-cp311-cp311-manylinux2014_x86_64.whl (319.4 kB view hashes)

Uploaded CPython 3.11

sproto-0.1.2-cp311-cp311-macosx_10_9_x86_64.whl (379.2 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

sproto-0.1.2-cp311-cp311-macosx_10_9_arm64.whl (374.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ ARM64

sproto-0.1.2-cp310-cp310-win_amd64.whl (275.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

sproto-0.1.2-cp310-cp310-manylinux2014_x86_64.whl (320.0 kB view hashes)

Uploaded CPython 3.10

sproto-0.1.2-cp310-cp310-macosx_11_0_x86_64.whl (285.5 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

sproto-0.1.2-cp310-cp310-macosx_10_9_arm64.whl (373.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ ARM64

sproto-0.1.2-cp39-cp39-win_amd64.whl (275.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

sproto-0.1.2-cp39-cp39-manylinux2014_x86_64.whl (320.0 kB view hashes)

Uploaded CPython 3.9

sproto-0.1.2-cp39-cp39-macosx_11_0_x86_64.whl (285.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

sproto-0.1.2-cp38-cp38-win_amd64.whl (275.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

sproto-0.1.2-cp38-cp38-manylinux2014_x86_64.whl (320.6 kB view hashes)

Uploaded CPython 3.8

sproto-0.1.2-cp38-cp38-macosx_11_0_x86_64.whl (285.5 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page