framed
numcodecs_combinators.framed
This module defines the FramedCodecStack class, which exposes a framed stack of codecs as a combined codec.
Classes:
-
FramedCodecStack–A framed stack of codecs, which makes up a combined codec.
FramedCodecStack
Bases: Codec, CodecCombinatorMixin, tuple[Codec]
A framed stack of codecs, which makes up a combined codec.
On encoding, the result of applying the codecs from left to right to encode is framed s.t. the data types and shapes of all arrays (input, intermediary, encoded) are stored as part of the encoding, which is output as a bytestring.
On decoding, this framing information is used to apply the codecs from right to left to decode into known output data types and shapes.
Therefore, the FramedCodecStack
can be used to combine codecs which require knowing the output data type
and shape during decoding. It can also be used to encode arrays into
bytestrings.
Unlike the CodecStack, this
class does not provide an additional encode_decode(buf) method, since
it is equivalent to framed.decode(stack.encode(buf)) due to the framing.
Methods:
-
encode–Encode the data in
buf. -
decode–Decode the data in
buf. -
get_config–Returns the configuration of the framed codec stack.
-
from_config–Instantiate the framed codec stack from a configuration
dict. -
map–Apply the
mapperto all codecs that are in this framed stack.
encode
encode(buf: Buffer) -> bytes
Encode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
decode
decode(buf: Buffer, out: Optional[Buffer] = None) -> Buffer
Decode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
get_config
get_config() -> dict
Returns the configuration of the framed codec stack.
numcodecs.registry.get_codec(config)
can be used to reconstruct this stack from the returned config.
| Returns: |
|
|---|
from_config
classmethod
from_config(config: dict) -> Self
Instantiate the framed codec stack from a configuration dict.
| Parameters: |
|
|---|
| Returns: |
|
|---|
map
map(mapper: Callable[[Codec], Codec]) -> FramedCodecStack
Apply the mapper to all codecs that are in this framed stack.
In the returned stack, each codec is replaced by its mapped codec.
The mapper should recursively apply itself to any inner codecs that
also implement the CodecCombinatorMixin
mixin.
To automatically handle the recursive application as a caller, you can use
numcodecs_combinators.map_codec(stack, mapper)
| Parameters: |
|---|
| Returns: |
|
|---|