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

Enables support for Protocol Buffer serialization in C code using protobuf-c. More...

Inherits org.lflang.federated.serialization.FedSerialization.

Public Member Functions

StringBuilder generateCompilerExtensionForSupport ()
StringBuilder generateNetworkDeserializerCode (String varName, String targetType)
 Generate code that deserializes a network message into a freshly heap-allocated protobuf message via __unpack.
StringBuilder generateNetworkSerializerCode (String varName, String originalType)
 Generate code that serializes the value of a pointer-typed port using __pack.
StringBuilder generatePortAssignmentCode (String receiveRef)
 Generate code that hands ownership of the deserialized message to the LF runtime via a token, so that protobuf_c_message_free_unpacked is invoked when the token's reference count drops to zero.
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 Member Functions

static String protobufCFunctionPrefix (String messageType)
 Convert a protobuf message type name to the protobuf-c function prefix.
static String stripPointer (String type)
 Strip trailing * characters from a C pointer type string.

Static Public Attributes

static final String deserializedVarName = "deserialized_message"
 Variable name in the target language for the deserialized data.
static final String PROTOBUF_DESTRUCTOR_NAME = "_lf_protobuf_destructor"
 Name of the generated destructor that frees a heap-allocated protobuf-c message.
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 C code using protobuf-c.

For federated connections that use serializer "proto", the port type must be a protobuf message pointer (e.g. MyMessage*). Sender reactions allocate and initialize messages on the heap; the runtime owns the lifetime of deserialized messages on the receiver side and frees them via org.lflang.federated.serialization.FedProtoCSerialization#PROTOBUF_DESTRUCTOR_NAME (a thin wrapper around protobuf_c_message_free_unpacked).

Author
Edward A. Lee

Member Function Documentation

◆ generateCompilerExtensionForSupport()

StringBuilder org.lflang.federated.serialization.FedProtoCSerialization.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.FedProtoCSerialization.generateNetworkDeserializerCode ( String varName,
String targetType )

Generate code that deserializes a network message into a freshly heap-allocated protobuf message via __unpack.

Parameters
varNameReference to the receiving action.
targetTypeThe protobuf message type name (without the trailing *).

Implements org.lflang.federated.serialization.FedSerialization.

◆ generateNetworkSerializerCode()

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

Generate code that serializes the value of a pointer-typed port using __pack.

Parameters
varNameReference to the port (e.g. msg[0]). The port's value field is expected to be a pointer to a protobuf message of type originalType.
originalTypeThe protobuf message type name (without the trailing *).

Implements org.lflang.federated.serialization.FedSerialization.

◆ generatePortAssignmentCode()

StringBuilder org.lflang.federated.serialization.FedProtoCSerialization.generatePortAssignmentCode ( String receiveRef)

Generate code that hands ownership of the deserialized message to the LF runtime via a token, so that protobuf_c_message_free_unpacked is invoked when the token's reference count drops to zero.

◆ generatePreambleForSupport()

StringBuilder org.lflang.federated.serialization.FedProtoCSerialization.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.FedProtoCSerialization.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.

◆ protobufCFunctionPrefix()

String org.lflang.federated.serialization.FedProtoCSerialization.protobufCFunctionPrefix ( String messageType)
static

Convert a protobuf message type name to the protobuf-c function prefix.

For example,
Person
becomes person and ProtoHelloWorld becomes proto_hello_world.

◆ serializedBufferLength()

String org.lflang.federated.serialization.FedProtoCSerialization.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.FedProtoCSerialization.serializedBufferVar ( )
Returns
Expression in target language that is the buffer variable itself.

Implements org.lflang.federated.serialization.FedSerialization.

◆ stripPointer()

String org.lflang.federated.serialization.FedProtoCSerialization.stripPointer ( String type)
static

Strip trailing * characters from a C pointer type string.

Member Data Documentation

◆ deserializedVarName

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

Variable name in the target language for the deserialized data.

◆ PROTOBUF_DESTRUCTOR_NAME

final String org.lflang.federated.serialization.FedProtoCSerialization.PROTOBUF_DESTRUCTOR_NAME = "_lf_protobuf_destructor"
static

Name of the generated destructor that frees a heap-allocated protobuf-c message.

◆ 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/FedProtoCSerialization.java