rsb.converter¶
Contains converter implementations and logic for registration and selection.
Code author: jmoringe
Code author: jwienke
Code author: plueckin
Functions
|
Get a map with all globally known converters for the |
|
|
|
Register |
Classes
A converter which just passes through the original byte array of a message. |
|
|
Handles byte arrays. |
|
Base class for converters to a certain target type. |
|
A class managing converters for for a certain target type. |
This class defines the interface for converter selection strategy classes. |
|
|
A converter for aggregated events ordered by their scope and time. |
Does nothing. |
|
Produces a serialized value that represents instances of |
|
|
Performs converter selection using a chain-of-responsibility strategy. |
|
Serializes and deserializes objects of protocol buffer data-holder classes. |
Passes through the wire_schema and the original byte array of a message. |
|
(De)serializes |
|
|
Serializes strings to bytes with a specified encoding. |
|
Exceptions
|
Raised in case a required converter cannot be found. |
-
exception
rsb.converter.
UnknownConverterError
(source_type, wire_schema)¶ Bases:
KeyError
Raised in case a required converter cannot be found.
Code author: jwienke
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
args
¶
-
-
class
rsb.converter.
BoolConverter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
ByteArrayConverter
¶ Bases:
rsb.converter.Converter
A converter which just passes through the original byte array of a message.
Code author: jwienke
-
deserialize
(data, wire_schema)¶
-
serialize
(data)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
BytesConverter
(wire_schema='bytes', data_type=<class 'bytes'>)¶ Bases:
rsb.converter.Converter
Handles byte arrays.
Code author: jmoringe
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
Converter
(wire_type, data_type, wire_schema)¶ Bases:
object
Base class for converters to a certain target type.
Code author: jwienke
Create a new instance.
- Parameters
wire_type – Python type to/from which the converter serializes/deserializes
data_type – Python type of data accepted by the converter for serialization (also Python type of deserialized data)
wire_schema – Wire-schema understood by the converter when deserializing (also wire-schema of data serialized with the converter)
- Type wire_type
types.TypeType
- Type data_type
types.TypeType
- Type wire_schema
str
-
abstract
deserialize
(inp, wire_schema)¶
-
abstract
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
class
rsb.converter.
ConverterMap
(wire_type)¶ Bases:
rsb.converter.ConverterSelectionStrategy
A class managing converters for for a certain target type.
Code author: jwienke
-
add_converter
(converter, replace_existing=False)¶
-
get_converter_for_data_type
(data_type)¶
-
get_converter_for_wire_schema
(wire_schema)¶
-
get_converters
()¶
-
has_converter_for_data_type
(data_type)¶
-
has_converter_for_wire_schema
(wire_schema)¶
-
property
wire_type
¶
-
-
class
rsb.converter.
ConverterSelectionStrategy
¶ Bases:
object
This class defines the interface for converter selection strategy classes.
Code author: jmoringe
-
get_converter_for_data_type
(data_type)¶
-
get_converter_for_wire_schema
(wire_schema)¶
-
has_converter_for_data_type
(data_type)¶
-
has_converter_for_wire_schema
(wire_schema)¶
-
-
class
rsb.converter.
DoubleConverter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
EventsByScopeMapConverter
(converter_repository=<rsb.converter.ConverterMap object>)¶ Bases:
rsb.converter.Converter
A converter for aggregated events ordered by their scope and time.
As a client data type dictionaries are used. Think about this when you register the converter and also have other dictionaries to transmit.
Code author: jwienke
-
deserialize
(wire, wire_schema)¶
-
serialize
(data)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
FloatConverter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
IdentityConverter
¶ Bases:
rsb.converter.Converter
Does nothing.
Serializes everything to an empty representation and always returns
None
.Use it in combination with the “always_applicable”-wire_schema.
Code author: plueckin
-
always_applicable
()¶
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
Int32Converter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
Int64Converter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
NoneConverter
¶ Bases:
rsb.converter.Converter
Produces a serialized value that represents instances of
NoneType
.Such a converter is required for serializing “results” of RPC calls that do not return a value.
Code author: jmoringe
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
PredicateConverterList
(wire_type)¶ Bases:
rsb.converter.ConverterMap
Performs converter selection using a chain-of-responsibility strategy.
A list of predicates and associated converters is maintained. Converter selection queries are processed by traversing the list and selected the first converter the associated predicate of which matches the query wire-schema or data-type.
Code author: jmoringe
-
add_converter
(converter, wire_schema_predicate=None, data_type_predicate=None, replace_existing=True)¶
-
get_converter_for_data_type
(data_type)¶
-
get_converter_for_wire_schema
(wire_schema)¶
-
get_converters
()¶
-
has_converter_for_data_type
(data_type)¶
-
has_converter_for_wire_schema
(wire_schema)¶
-
property
wire_type
¶
-
-
class
rsb.converter.
ProtocolBufferConverter
(message_class)¶ Bases:
rsb.converter.Converter
Serializes and deserializes objects of protocol buffer data-holder classes.
These data-holder classes are generated by the protocol buffer compiler protoc.
Code author: jmoringe
-
deserialize
(inp, wire_schema)¶
-
get_message_class_name
()¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
message_class
¶
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
SchemaAndByteArrayConverter
¶ Bases:
rsb.converter.Converter
Passes through the wire_schema and the original byte array of a message.
Code author: nkoester
-
deserialize
(data, wire_schema)¶
-
serialize
(data)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
ScopeConverter
¶ Bases:
rsb.converter.Converter
(De)serializes
Scope
objects.Code author: jmoringe
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
StringConverter
(wire_schema='utf-8-string', encoding='utf-8')¶ Bases:
rsb.converter.Converter
Serializes strings to bytes with a specified encoding.
Code author: jwienke
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
Uint32Converter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
Uint64Converter
¶ Bases:
rsb.converter.Converter
-
deserialize
(inp, wire_schema)¶
-
serialize
(inp)¶
-
property
data_type
¶ Return the data type this converter is applicable for.
- Returns
A type object.
- Rtype
types.TypeType
-
property
wire_schema
¶ Return the name of the wire schema this converter can (de)serialize.
- Returns
A string designating the wire schema from/to this converter can (de)serialize
- Rtype
str
-
property
wire_type
¶ Return the type of the wire-type of this converter.
The wire-type is the data type to/from which this converter serializes/deserializes.
- Returns
A type object.
- Rtype
types.TypeType
-
-
class
rsb.converter.
UnambiguousConverterMap
(wire_type)¶ Bases:
rsb.converter.ConverterMap
-
add_converter
(converter, replace_existing=False)¶
-
get_converter_for_data_type
(data_type)¶
-
get_converter_for_wire_schema
(wire_schema)¶
-
get_converters
()¶
-
has_converter_for_data_type
(data_type)¶
-
has_converter_for_wire_schema
(wire_schema)¶
-
property
wire_type
¶
-
-
rsb.converter.
get_global_converter_map
(wire_type)¶ Get a map with all globally known converters for the
wire_type
.- Parameters
wire_type – Python type for designating the wire-type.
- Type wire_type
types.TypeType
- Returns
converter map constantly updated
-
rsb.converter.
make_struct_based_converter
(name, data_type, wire_schema, fmt, size)¶
-
rsb.converter.
register_global_converter
(converter, replace_existing=False)¶ Register
converter
as a globally available converter.- Parameters
converter – converter to register
replace_existing – controls whether an existing converter for the same data-type and/or wire-type should be replaced by the new converter. If this is
False
and such a converter exists, an error is raised.