Skip to main content

No project description provided

Project description

Length-Delimited Proto

When protobuf messages are either across the wire, or put in intermediary storage, it is helpful to be able to read and write individual messages in a streaming format.

This package exposes two methods:

  • write_ld(writer, protomsg) - writes one instance of a protobuf message to the stream
  • read_ld(reader, msgtype) -> protomsg - reads one protobuf message from the stream, using the type as the constructor

This package uses an unsigned 32-bit integer as the length-prefix.

Example

Assuming there is a protobuf message with the type name "User"

from ldproto import read_ld, write_ld
import myproto as pb

# .ld is for length-delimited
with open('out.user.ld', 'wb') as f:
    for user in users:
        write_ld(f, user)

pb_users = []
with open('out.user.ld', 'rb') as f:
    for pb_user in read_ld(f, pb.User):
        pb_users.append(user)

To write to / from a bytestream in-memory, use BytesIO in-place of the files in the example.

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

ldproto-0.1.11.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

ldproto-0.1.11-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

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