lingua-franca 0.10.1
Lingua Franca code generator
Loading...
Searching...
No Matches
org.lflang.federated.serialization.FedProtoPythonSerialization Class Reference

Enables support for Protocol Buffer serialization in Python federated programs. More...

Inherits org.lflang.federated.serialization.FedSerialization.

Public Member Functions

StringBuilder generateCompilerExtensionForSupport ()
StringBuilder generateNetworkDeserializerCode (String varName, String targetType)
 Generate C code that deserializes a wire buffer into a Python proto object.
StringBuilder generateNetworkSerializerCode (String varName, String originalType)
 Generate C code that serializes a Python proto object into a self-describing wire buffer.
StringBuilder generatePreambleForSupport ()
boolean isCompatible (GeneratorBase generator)
 Check whether the current generator is compatible with the given serialization technique or not.
String serializedBufferLength ()
String serializedBufferVar ()

Static Public Attributes

static final String BUF_VAR = "_lf_proto_wire_buf"
 Name of the malloc'd wire-format buffer variable in generated C code.
static final String deserializedVarName = "deserialized_message"
 Variable name in the target language for the deserialized data.
static final String LEN_VAR = "_lf_proto_wire_len"
 Name of the wire-format buffer length variable in generated C code.
static final String serializedVarName = "serialized_message"
 Variable name in the target language for the serialized data.

Detailed Description

Enables support for Protocol Buffer serialization in Python federated programs.

User reactions work with proto objects directly (no manual SerializeToString / ParseFromString calls). The generated C code:

  • Sender: calls SerializeToString() on the Python proto object and prepends the message's fully-qualified type name so the receiver can reconstruct the right class.
  • Receiver: reads the type name from the wire format, uses Python's
    google.protobuf.symbol_database
    to obtain the class, creates an instance, and calls ParseFromString().

Wire format: [4-byte big-endian name length][UTF-8 full_name][proto bytes]

Author
Hokeun Kim

Member Function Documentation

◆ generateCompilerExtensionForSupport()

StringBuilder org.lflang.federated.serialization.FedProtoPythonSerialization.generateCompilerExtensionForSupport ( )
Returns
Code that should be appended to the compiler instructions (e.g., flags to gcc or additional lines to a CMakeLists.txt) to enable support for the current serializer.

Implements org.lflang.federated.serialization.FedSerialization.

◆ generateNetworkDeserializerCode()

StringBuilder org.lflang.federated.serialization.FedProtoPythonSerialization.generateNetworkDeserializerCode ( String varName,
String targetType )

Generate C code that deserializes a wire buffer into a Python proto object.

The type name embedded in the wire format is used to look up the proto class via Python's google.protobuf.symbol_database, so no port-type annotation is required.

Parameters
varNameThe action variable name (accessed as varName->token->value).
targetTypeUnused.

Implements org.lflang.federated.serialization.FedSerialization.

◆ generateNetworkSerializerCode()

StringBuilder org.lflang.federated.serialization.FedProtoPythonSerialization.generateNetworkSerializerCode ( String varName,
String originalType )

Generate C code that serializes a Python proto object into a self-describing wire buffer.

Wire format: [4-byte big-endian name_len][full_name bytes][proto bytes]

The caller is responsible for calling free(_lf_proto_wire_buf) after the buffer has been sent.

Parameters
varNameC expression for the Python proto object (e.g. sendRef->value).
originalTypeUnused.

Implements org.lflang.federated.serialization.FedSerialization.

◆ generatePreambleForSupport()

StringBuilder org.lflang.federated.serialization.FedProtoPythonSerialization.generatePreambleForSupport ( )
Returns
Code in target language that includes all the necessary preamble to enable support for the current serializer.

Implements org.lflang.federated.serialization.FedSerialization.

◆ isCompatible()

boolean org.lflang.federated.serialization.FedProtoPythonSerialization.isCompatible ( GeneratorBase generator)

Check whether the current generator is compatible with the given serialization technique or not.

Parameters
generatorThe current generator.
Returns
true if compatible, false if not.

Implements org.lflang.federated.serialization.FedSerialization.

◆ serializedBufferLength()

String org.lflang.federated.serialization.FedProtoPythonSerialization.serializedBufferLength ( )
Returns
Expression in target language that corresponds to the length of the serialized buffer.

Implements org.lflang.federated.serialization.FedSerialization.

◆ serializedBufferVar()

String org.lflang.federated.serialization.FedProtoPythonSerialization.serializedBufferVar ( )
Returns
Expression in target language that is the buffer variable itself.

Implements org.lflang.federated.serialization.FedSerialization.

Member Data Documentation

◆ BUF_VAR

final String org.lflang.federated.serialization.FedProtoPythonSerialization.BUF_VAR = "_lf_proto_wire_buf"
static

Name of the malloc'd wire-format buffer variable in generated C code.

◆ deserializedVarName

final String org.lflang.federated.serialization.FedSerialization.deserializedVarName = "deserialized_message"
staticinherited

Variable name in the target language for the deserialized data.

◆ LEN_VAR

final String org.lflang.federated.serialization.FedProtoPythonSerialization.LEN_VAR = "_lf_proto_wire_len"
static

Name of the wire-format buffer length variable in generated C code.

◆ serializedVarName

final String org.lflang.federated.serialization.FedSerialization.serializedVarName = "serialized_message"
staticinherited

Variable name in the target language for the serialized data.


The documentation for this class was generated from the following file:
  • /Users/runner/work/lingua-franca/lingua-franca/core/src/main/java/org/lflang/federated/serialization/FedProtoPythonSerialization.java