Operator Serializer
The Serlizer operator serializes input tuples in network byte order and emits tuples with an attribute of a blob or rstring to the output port.
All attributes of the input tuple are serialized by default. To control which attributes are serialized and emitted, use the inputAttributes parameter.
Beyond the attribute values, the serialization result emitted may include type information at the beginning of the payload to validate transmission configuration on the receiver side. By default, every 100th tuple emitted contains type information in the payload. The type information can be included in every payload by setting the activateTypeList parameter to true. Otherwise, the iterateTypeListCount parameter can be used to control how frequent the type information is present.
Examples
use com.teracloud.streams.inet.util::*;
public composite Main {
graph
stream<rstring firstName, rstring lastName, uint8 age> Input = Beacon() {}
// Serialize all input tuples
stream<blob binaryData> AllStream = Serializer(Input) {
output AllSerializedStream:
binaryData = serialized();
}
// Serialize select tuples and include type info in every payload
stream<uint64 sequence, blob binaryData> SelectStream = Serializer(Input) {
param
inputAttributes: firstName, age;
activateTypeList: true;
output SelectStream:
sequence = sequence();
binaryData = serialized();
}
}
Summary
- Ports
- This operator has 1 input port and 1 output port.
- Windowing
- This operator does not accept any windowing configurations.
- Parameters
- This operator supports 3 parameters.
Optional: activateTypeList, inputAttributes, iterateTypeListCount
- Metrics
- This operator does not report any metrics.
Properties
- Implementation
- C++
- Threading
- Always - Operator always provides a single threaded execution context.
- Ports (0)
-
The tuples of this single input port are serialized and the serialization result is emitted as a blob to the output port.
- Properties
-
- Optional: false
- ControlPort: false
- TupleMutationAllowed: false
- WindowingMode: NonWindowed
- WindowPunctuationInputMode: Oblivious
- Assignments
- This operator allows any SPL expression of the correct type to be assigned to output attributes. Attributes not assigned in the output clause will be automatically assigned from the attributes of the input ports that have the same name and type. If there is no such input attribute, an error is reported at compile-time.
- Output Functions
-
- SerializeFunctions
-
- <any T> T AsIs(T)
-
The default function for output attributes. This function assigns the output attribute to the value of the input attribute with the same name.
- <any T> T serialized()
-
Get the serialized data payload. The output attribute type must be rstring or blob.
- uint64 sequence()
-
Sequence number of the output tuple. Starts with zero. Must be of type uint64.
- Ports (0)
-
The output port with the serialized data. With output function serialized the serialized data can be assigned to output attributes. With output function sequence the sequence number can be assigned to an attribute. All other attributes are assigned from input tuple.
- Properties
-
- Optional: false
- TupleMutationAllowed: true
- WindowPunctuationOutputMode: Free
Optional: activateTypeList, inputAttributes, iterateTypeListCount
- activateTypeList
-
If this parameter is true, a type list information is inserted into the serialized data block. Default is false.
- Properties
-
- Type: boolean
- Cardinality: 1
- Optional: true
- ExpressionMode: Attribute
- inputAttributes
-
This parameter specifies the attributes of the input stream to serialize. If this parameter is absent, all input attributes will be included in the serialized output blob/rstring.
Note: The serialization sequence of the input attributes corresponds to the sequence of this parameter. If this parameter is absent, the attribute sequence of the input tuple is significant.
- Properties
-
- Optional: true
- ExpressionMode: Attribute
- iterateTypeListCount
-
This parameter controls how often the type list information is embedded in the serialization data block. The operator inserts type information every iterateTypeListCount tuple. If the value is zero, no type list information is inserted. Default is 100.
- Properties
-
- Type: uint32
- Cardinality: 1
- Optional: true
- ExpressionMode: AttributeFree
- Serializer
-
stream<${schema}> ${outputStream} = com.teracloud.streams.inet.util::Serializer(${inputStream}) { param ${parameter}: ${parameterExpression}; output ${outputStream}: ${outputAttribute} = ${value}; }