Serializer Module API Reference¶
This section documents the internals of the serializer
module in Bijux CLI.
bijux_cli.contracts.serializer ¶
Defines the contract for the object serialization service.
This module specifies the SerializerProtocol
, a formal interface that any service responsible for serializing objects to strings or bytes (e.g., in JSON or YAML format) and deserializing them back must implement.
SerializerProtocol ¶
Bases: Protocol[T]
Defines the contract for stateless, thread-safe object serialization.
This interface specifies methods for serializing and deserializing objects to and from strings or bytes in various formats, such as JSON or YAML.
dumps ¶
dumps(
obj: T,
*,
fmt: OutputFormat = JSON,
pretty: bool = False,
) -> str
Serializes an object to a string.
Parameters:
-
obj
(T
) –The object to serialize.
-
fmt
(OutputFormat
, default:JSON
) –The output format. Defaults to
OutputFormat.JSON
. -
pretty
(bool
, default:False
) –If True, formats the output for human readability.
Returns:
-
str
(str
) –The serialized object as a string.
Source code in src/bijux_cli/contracts/serializer.py
dumps_bytes ¶
dumps_bytes(
obj: T,
*,
fmt: OutputFormat = JSON,
pretty: bool = False,
) -> bytes
Serializes an object to bytes.
Parameters:
-
obj
(T
) –The object to serialize.
-
fmt
(OutputFormat
, default:JSON
) –The output format. Defaults to
OutputFormat.JSON
. -
pretty
(bool
, default:False
) –If True, formats the output for human readability.
Returns:
-
bytes
(bytes
) –The serialized object as bytes.
Source code in src/bijux_cli/contracts/serializer.py
emit ¶
emit(
payload: T,
*,
fmt: OutputFormat = JSON,
pretty: bool = False,
) -> None
Serializes and emits a payload to standard output.
Parameters:
-
payload
(T
) –The object to serialize and emit.
-
fmt
(OutputFormat
, default:JSON
) –The output format.
-
pretty
(bool
, default:False
) –If True, formats the output for human readability.
Returns:
-
None
(None
) –
Source code in src/bijux_cli/contracts/serializer.py
loads ¶
loads(
data: str | bytes,
*,
fmt: OutputFormat = JSON,
pretty: bool = False,
) -> T
Deserializes data from a string or bytes into an object.
Parameters:
-
data
(str | bytes
) –The string or bytes to deserialize.
-
fmt
(OutputFormat
, default:JSON
) –The format of the input data. Defaults to
OutputFormat.JSON
. -
pretty
(bool
, default:False
) –A hint that may affect parsing, though often unused during deserialization.
Returns:
-
T
(T
) –The deserialized object.