Netstrings

The netstrings module provides a way of sending strings across a network.

Netstrings are a way of framing arbitrarily long strings so they can be sent over a socket. The netstring specification is very simple.

turberfield.ipc.netstrings.dumpb(data: str, encoding=’utf-8’)[source]

Convert a string to its netstring representation. Returns a bytes object.

turberfield.ipc.netstrings.loadb(encoding=’utf-8’)[source]

This function is a generator. It accepts bytes data via its send method. Like all generators, it must be primed before use by sending None:

decoder = loadb()
decoder.send(None)

The generator will yield an object whenever it has collected a complete netstring message:

msg is None
while msg is None:
    msg = decoder.send(packet)
else:
    print(msg)