dataclass
Dataclass codec registration (internal).
This module registers GenericDataClassCodec for the public dataclasses that
may cross the main↔worker boundary (primarily result container types and formula
DSL nodes).
The registry is populated at process startup via get_default_registry().
Attributes¶
_generics = [_all_types.RListVectorExtension]
module-attribute
¶
_classes = [t for name, t in (_all_types.__dict__.items()) if isinstance(t, type) and is_dataclass(t) and t not in _generics]
module-attribute
¶
Classes¶
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.
Source code in brmspy/_session/codec/base.py
GenericDataClassCodec
¶
Bases: Encoder
Generic codec for dataclasses (internal).
Encodes each init=True field by delegating to a
CodecRegistry. Use skip_fields to exclude
fields that must not cross the boundary.
Source code in brmspy/_session/codec/builtin.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
Attributes¶
_cls = cls
instance-attribute
¶
_registry = registry
instance-attribute
¶
codec = f'dataclass::{cls.__module__}.{cls.__qualname__}'
instance-attribute
¶
_skip_fields = skip_fields or set()
instance-attribute
¶
_field_names = []
instance-attribute
¶
Functions¶
__init__(cls, registry, *, skip_fields=None)
¶
Source code in brmspy/_session/codec/builtin.py
can_encode(obj)
¶
encode(obj, shm_pool)
¶
Source code in brmspy/_session/codec/builtin.py
decode(payload, get_buf, *args)
¶
Source code in brmspy/_session/codec/builtin.py
Functions¶
register_dataclasses(registry)
¶
Register codecs for known dataclass types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
CodecRegistry
|
Registry to populate. |
required |