zoonado.protocol.primitives

class zoonado.protocol.primitives.Primitive(value)[source]

The most basic structure of the protocol. Subclassed, never used directly.

Used as a building block for the various actually-used primitives outlined in the Zookeeper jute file:

https://github.com/apache/zookeeper/blob/trunk/src/zookeeper.jute

render()[source]

Returns a two-element tuple with the struct format and list value.

The value is wrapped in a list, as there are some primitives that deal with multiple values. Any caller of render() should expect a list.

classmethod parse(buff, offset)[source]

Given a buffer and offset, returns the parsed value and new offset.

Uses the format class attribute to unpack the data from the buffer and determine the used up number of bytes.

class zoonado.protocol.primitives.VariablePrimitive(value)[source]

Base primitive for variable-length scalar primitives (strings and bytes).

render()[source]

Returns the struct format and list of the size and value.

The format is derived from the size primitive and the length of the resulting encoded value (e.g. the format for a string of ‘foo’ ends up as ‘h3s’.

Note

The value is expected to be string-able (wrapped in str()) and is then encoded as UTF-8.

classmethod parse(buff, offset)[source]

Given a buffer and offset, returns the parsed value and new offset.

Parses the size_primitive first to determine how many more bytes to consume to extract the value.

class zoonado.protocol.primitives.Bool(value)[source]

Represents a boolean (true or false) value.

Renders as an unsigned char (1 byte).

class zoonado.protocol.primitives.Byte(value)[source]

Represents a single 8-bit byte.

class zoonado.protocol.primitives.Int(value)[source]

Represents an 32-bit signed integer.

class zoonado.protocol.primitives.Long(value)[source]

Represents an 64-bit signed integer.

class zoonado.protocol.primitives.Float(value)[source]

Represents a single-precision floating poing conforming to IEEE 754.

class zoonado.protocol.primitives.Double(value)[source]

Represents a double-precision floating poing conforming to IEEE 754.

class zoonado.protocol.primitives.UString(value)[source]

Represents a unicode string value, length denoted by a 32-bit integer.

size_primitive

alias of Int

class zoonado.protocol.primitives.Buffer(value)[source]

Represents a bytestring value, length denoted by a 32-bit signed integer.

size_primitive

alias of Int

class zoonado.protocol.primitives.Vector(value)[source]

Represents an array of any arbitrary Primitive or Part.

Not used directly but rather by its of() classmethod to denote an Vector.of(<something>).

classmethod of(part_class)[source]

Creates a new class with the item_class attribute properly set.

render()[source]

Creates a composite struct format and the data to render with it.

The format and data are prefixed with a 32-bit integer denoting the number of elements, after which each of the items in the array value are render()-ed and added to the format and data as well.

classmethod parse(buff, offset)[source]

Parses a raw buffer at offset and returns the resulting array value.

Starts off by parse()-ing the 32-bit element count, followed by parsing items out of the buffer “count” times.