pycozmo.protocol_utils¶
Cozmo protocol encoding helper classes and functions.
Functions
get_farray_size(fmt, length) |
Figures out the size of a fixed array with given format. |
get_object_farray_size(value, length) |
Figures out the size of a given fixed-length object sequence. |
get_object_size(value) |
Figures out the size of a given object. |
get_size(fmt) |
Figures out the size of a value with the given format. |
get_string_size(value, length_format) |
Figures out the size of a string with given length format. |
get_varray_size(value, length_format, …) |
Figures out the size of a variable-length array with given format. |
validate_bool(name, value) |
|
validate_farray(name, value, length, …) |
|
validate_float(name, value) |
|
validate_integer(name, value, minimum, maximum) |
|
validate_object(name, value, expected_type) |
|
validate_string(name, value, maximum_length) |
|
validate_varray(name, value, maximum_length, …) |
Classes
BinaryReader(buffer, offset) |
Used to read in a stream of binary data, keeping track of the current position. |
BinaryWriter() |
Used to write out a stream of binary data. |
-
pycozmo.protocol_utils.validate_float(name, value)¶
-
pycozmo.protocol_utils.validate_bool(name, value)¶
-
pycozmo.protocol_utils.validate_integer(name, value, minimum, maximum)¶
-
pycozmo.protocol_utils.validate_object(name, value, expected_type)¶
-
pycozmo.protocol_utils.validate_farray(name, value, length, element_validation)¶
-
pycozmo.protocol_utils.validate_varray(name, value, maximum_length, element_validation)¶
-
pycozmo.protocol_utils.validate_string(name, value, maximum_length)¶
-
pycozmo.protocol_utils.get_size(fmt)¶ Figures out the size of a value with the given format.
-
pycozmo.protocol_utils.get_farray_size(fmt, length)¶ Figures out the size of a fixed array with given format.
-
pycozmo.protocol_utils.get_varray_size(value, length_format, data_format)¶ Figures out the size of a variable-length array with given format.
-
pycozmo.protocol_utils.get_string_size(value, length_format)¶ Figures out the size of a string with given length format.
-
pycozmo.protocol_utils.get_object_size(value)¶ Figures out the size of a given object.
-
pycozmo.protocol_utils.get_object_farray_size(value, length)¶ Figures out the size of a given fixed-length object sequence.
-
class
pycozmo.protocol_utils.BinaryReader(buffer: bytes, offset: int = 0)¶ Bases:
objectUsed to read in a stream of binary data, keeping track of the current position.
-
buffer¶
-
read(fmt)¶ Reads in a single value of the given format.
-
read_farray(fmt, length)¶ Reads in a fixed-length array of the given format and length.
-
read_object(from__reader_method)¶ Reads in an object according to the given method.
-
read_object_farray(from__reader_method, length)¶ Reads in a fixed-length object sequence according to the given method.
-
read_object_varray(from__reader_method, length_format)¶ Reads in a variable-length object sequence according to the given method.
-
read_string(length_format)¶ Reads in a variable-length string with the given length format.
-
read_string_farray(string_length_format, array_length)¶ Reads in a fixed-length array of variable-length strings with the given length format.
-
read_string_varray(string_length_format, array_length_format)¶ Reads in a variable-length array of variable-length strings with the given length format.
-
read_varray(data_format, length_format)¶ Reads in a variable-length array with the given length format and data format.
-
seek_cur(offset: int) → None¶
-
seek_set(offset: int) → None¶
-
tell()¶ Returns the current stream position as an offset within the buffer.
-
-
class
pycozmo.protocol_utils.BinaryWriter¶ Bases:
objectUsed to write out a stream of binary data.
-
clear()¶
-
dumps() → bytes¶
-
write(value, fmt)¶ Writes out a single value of the given format.
-
write_bytes(value: bytes) → None¶ Writes out a byte sequence.
-
write_farray(value, fmt, length)¶ Writes out a fixed-length array of the given format and length.
-
write_object(value)¶ Writes out an object that supports a to_writer() method.
-
write_object_farray(value, length)¶ Writes out a fixed-length object sequence that supports a to_writer() method.
-
write_object_varray(value, length_format)¶ Writes out a variable-length object sequence that supports a to_writer() method.
-
write_string(value, length_format)¶ Writes out a variable-length string with the given length format.
-
write_string_farray(value, string_length_format, array_length)¶ Writes out a fixed-length array of variable-length strings with the given length format.
-
write_string_varray(value, string_length_format, array_length_format)¶ Writes out a variable-length array of variable-length strings with the given length format.
-
write_varray(value, data_format, length_format)¶ Writes out a variable-length array with the given length format and data format.
-