stack
numcodecs_combinators.stack
This module defines the CodecStack class, which exposes a stack of codecs as a combined codec.
Classes:
-
CodecStack–A stack of codecs, which makes up a combined codec.
CodecStack
Bases: Codec, CodecCombinatorMixin, tuple[Codec]
A stack of codecs, which makes up a combined codec.
On encoding, the codecs are applied to encode from left to right, i.e.
CodecStack(a, b, c).encode(buf)
c.encode(b.encode(a.encode(buf)))
On decoding, the codecs are applied to decode from right to left, i.e.
CodecStack(a, b, c).decode(buf)
a.decode(b.decode(c.decode(buf)))
The CodecStack provides the
additional
encode_decode(buf)
method that computes
stack.decode(stack.encode(buf))
Methods:
-
encode–Encode the data in
buf. -
decode–Decode the data in
buf. -
encode_decode–Encode, then decode the data in
buf. -
encode_decode_data_array–Encode, then decode the data array in
da. -
get_config–Returns the configuration of the codec stack.
-
from_config–Instantiate the codec stack from a configuration
dict. -
map–Apply the
mapperto all codecs that are in this stack.
encode
encode(buf: Buffer) -> Buffer
Encode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
decode
decode(buf: Buffer, out: Optional[Buffer] = None) -> Buffer
Decode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
encode_decode
encode_decode(buf: Buffer) -> Buffer
Encode, then decode the data in buf.
| Parameters: |
|
|---|
| Returns: |
|
|---|
encode_decode_data_array
get_config
get_config() -> dict
Returns the configuration of the 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 codec stack from a configuration dict.
| Parameters: |
|
|---|
| Returns: |
|
|---|
map
map(mapper: Callable[[Codec], Codec]) -> CodecStack
Apply the mapper to all codecs that are in this 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: |
|
|---|