-
Notifications
You must be signed in to change notification settings - Fork 3
Python API reference
Main module of Compost
Bases: int
Unsigned bit precise integer
classmethod pack(buffer: memoryview, offset: MemUnit, value: int)
Serializes integer numeric type to specific bit offset in the buffer. The value may be packed to lower bit-size.
classmethod unpack(buffer: memoryview, offset: MemUnit)
class compost_rpc.CCodeGenerator(protocol: type[Protocol])
Bases: CodeGenerator
property features : CodeGeneratorFeatures
Features that the generator supports
generate(endpoint: Endpoint = Endpoint.REMOTE)
Generates the source code as a list of filepaths and string contents. :param endpoint: The endpoint to generate the code for. :type endpoint: Endpoint
Full long name of the language
Path used for generated source files.
Change path where the header file (.h) will be generated.
Change path where the source file (.c) will be generated.
Short name used for user input
class compost_rpc.CSharpCodeGenerator(protocol: type[Protocol])
Bases: CodeGenerator
property features : CodeGeneratorFeatures
Features that the generator supports
generate(endpoint: Endpoint = Endpoint.LOCAL)
Generates the source code as a list of filepaths and string contents. :param endpoint: The endpoint to generate the code for. :type endpoint: Endpoint
If true, the protocol class is declared as partial.
Full long name of the language
Specifies the namespace for the generated code.
Short name used for user input
If true, the arguments for InvokeRpcAsync will be passed as collection expression (C# 12 and later) instead of collection initializer.
If true, the mandatory protocol constructor will be generated as primary constructor (C# 12 and later).
class compost_rpc.CallDirection(value, names=, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases: Enum
class compost_rpc.CodeGenerator(protocol: type[Protocol])
Bases: ABC
abstract property features : CodeGeneratorFeatures
Features that the generator supports
Filename used for generated source files.
abstract generate(endpoint: Endpoint)
Generates the source code as a list of filepaths and string contents. :param endpoint: The endpoint to generate the code for. :type endpoint: Endpoint
Full long name of the language
Filename used for generated source files.
Short name used for user input
class compost_rpc.CodeGeneratorFeatures(inbound_remote: bool, outbound_remote: bool, inbound_notification: bool, outbound_notification: bool)
Bases: object
Target language can handle incoming notifications
Target language can handle incoming RPC calls
Target language can invoke notification
Target language can invoke RPC
Bases: bytes
Represents dynamically sized array of U8
Bases: str
String based on the compost_slice_u8
class compost_rpc.Endpoint(value, names=, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases: Enum
is_call_inbound(call: Rpc)
is_call_outbound(call: Rpc)
Bases: float
32-bit floating point number
Bases: float
64-bit floating point number
class compost_rpc.Generator(protocol: type[Protocol])
Bases: object
property c : CCodeGenerator
property csharp : CSharpCodeGenerator
If true, existing files will be overwritten without prompt.
Bases: object
Compost message header
Returns the length of the message in bytes.
Returns the length of the payload in bytes.
Bases: int
16-bit signed integer
Bases: int
32-bit signed integer
Bases: int
64-bit signed integer
Bases: int
8-bit signed integer
Bases: object
Represents a memory size that can be specified in bits or bytes. Now immutable.
Aligns the MemUnit to the next byte boundary if not already aligned.
class compost_rpc.Msg(header: Header, payload: bytes)
Bases: object
Raw Compost message that does not know the meaning of the payload.
Bases: object
class compost_rpc.Protocol(transport: Transport, timeout: float = 1)
Bases: object
Bases: Transport
Receives Compost message over the transport
Sends Compost message over the transport
Bases: RpcError
Received error message instead of a result.
Bases: RpcError
Response not received in time.
class compost_rpc.Rpc(rpc_id: int, name: str, req_serdes: PayloadSerdes, resp_serdes: PayloadSerdes, call_sig: Signature, is_notification: bool, direction: CallDirection, doc: str | None)
Bases: object
Bases: Exception
Generic RPC error.
Bases: Protocol[P, R]
Bases: Transport
Receives Compost message over the transport
Sends Compost message over the transport
Bases: Transport
Receives Compost message over the transport
Sends Compost message over the transport
Bases: Transport
Receives Compost message over the transport
Sends Compost message over the transport
Bases: Protocol
Receives Compost message over the transport
Sends Compost message over the transport
Bases: int
16-bit unsigned integer
Bases: int
32-bit unsigned integer
Bases: int
64-bit unsigned integer
Bases: int
8-bit unsigned integer
Bases: Transport
Receives Compost message over the transport
Sends Compost message over the transport
Bases: RpcError
Received unexpected txn value.
Bases: RpcError
Remote does not know the rpc_id. Incompatible protocol.
Decorator for enums to make them usable with Compost RPC defintions.
Use this for enum definitions ala C.
Example:
from compost_rpc import enum
@enum
class OtaResult(I8, Enum):
OTA_OK = 0
OTA_ERR = 1
compost_rpc.notification(rpc_id: int, direction: CallDirection = CallDirection.TO_LOCAL)
Registers function as notification.
Example:
from compost_rpc import struct
@struct
class LogMessage:
severity: U8
tag: U8
message: list[U8]
@notification(0x100)
def notify_log(self, log: LogMessage):
"""Sends the log message."""
Serializes Python objects in arguments to bytes
compost_rpc.rpc(rpc_id: int, notification: bool = False, direction: CallDirection = CallDirection.TO_REMOTE)
Registers function as remotely callable.
Example:
from compost_rpc import rpc
@rpc(0x001)
def read8(self, address: U32) -> U8:
"""Reads 8 bits of data from the specified address"""
Decorator for classes to make them usable with Compost RPC definitions.
Use this for structure definitions ala C.
Example:
from compost_rpc import struct
@struct
class OtaCoreLoad:
core0: I8
core1: I8
dsph: I8
Deserializes message payload into a tuple of Python objects