base
Classes¶
Encoder
¶
Bases: Protocol
Protocol implemented by codecs in the session codec registry.
Source code in brmspy/types/session.py
EncodeResult
dataclass
¶
Result of encoding a Python value for IPC transfer.
Attributes:
| Name | Type | Description |
|---|---|---|
codec |
str
|
Codec identifier. |
meta |
dict[str, Any]
|
JSON-serializable metadata required for decoding. |
buffers |
list[ShmRef]
|
Shared-memory blocks backing the encoded payload. |
Source code in brmspy/types/session.py
PayloadRef
¶
Bases: TypedDict
Encoded argument/result payload sent over the control pipe.
A payload is:
codec: the codec identifier used by the registrymeta: JSON-serializable metadata needed to reconstruct the valuebuffers: shared-memory buffer references backing the payload
Source code in brmspy/types/session.py
ShmBlock
dataclass
¶
Attached shared-memory block (name/size + live SharedMemory handle).
Notes
This object owns a SharedMemory handle and must be closed when no longer
needed. In brmspy this is managed by a ShmPool implementation.
Source code in brmspy/types/shm.py
ShmRef
¶
Bases: TypedDict
Reference to a shared-memory block sent over IPC.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Shared memory block name (as assigned by |
size |
int
|
Allocated block size in bytes. |
content_size |
int
|
Actual used size |
temporary |
bool
|
Whether this buffer can be GC-d immediately after use or should it be attached to object its constructed into. |
Notes
Codecs may store a logical payload smaller than size. In that case, the
codec metadata must include the logical nbytes/length so that decoders can
slice the buffer appropriately.
Source code in brmspy/types/shm.py
CodecRegistry
¶
Ordered registry of encoders used for IPC serialization.
Source code in brmspy/_session/codec/base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
Attributes¶
_by_codec = {}
instance-attribute
¶
_encoders = []
instance-attribute
¶
Functions¶
__init__()
¶
register(encoder)
¶
Register an encoder instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder
|
Encoder
|
Encoder to register. Its |
required |
Source code in brmspy/_session/codec/base.py
encode(obj, shm_pool)
¶
Encode an object by selecting the first encoder that accepts it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Value to encode. |
required |
shm_pool
|
Any
|
SHM pool used by codecs for allocating buffers. |
required |
Returns:
| Type | Description |
|---|---|
EncodeResult
|
|
Source code in brmspy/_session/codec/base.py
decode(payload, shm_pool)
¶
Decode a payload using a named codec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codec
|
str
|
Codec identifier previously returned by |
required |
meta
|
dict[str, Any]
|
Codec metadata. |
required |
buffers
|
list[memoryview]
|
Memoryviews for attached SHM buffers. |
required |
buffer_specs
|
list[dict]
|
Original buffer specs (name/size) corresponding to |
required |
shm_pool
|
Any
|
SHM pool (some codecs may attach additional buffers). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
|
Source code in brmspy/_session/codec/base.py
_attach_shm_lifetime(obj, shms)
classmethod
¶
Keep SHM blocks alive as long as obj is alive.