Skip to main content

TagBytes

This class provides a mechanism for encoding and decoding byte strings within a JSON structure. It identifies byte objects, converts them to Base64-encoded ASCII strings for JSON serialization, and restores them to their original byte format during deserialization.

Attributes​

AttributeTypeDescription
keystring = bThe unique tag identifier used in JSON serialization to denote that a value represents a base64-encoded byte string.

Methods​


check()​

@classmethod
def check(
value: t.Any
) - > bool

Determines if the provided value is a byte string, identifying it as compatible with this tag's serialization logic.

Parameters​

NameTypeDescription
valuet.AnyThe object to be checked for compatibility with byte serialization

Returns​

TypeDescription
boolTrue if the value is an instance of bytes, otherwise False

to_json()​

@classmethod
def to_json(
value: t.Any
) - > t.Any

Encodes a byte string into a base64-encoded ASCII string suitable for JSON serialization.

Parameters​

NameTypeDescription
valuet.AnyThe byte string to be converted into a JSON-safe format

Returns​

TypeDescription
t.AnyA base64-encoded ASCII string representing the original byte data

to_python()​

@classmethod
def to_python(
value: t.Any
) - > t.Any

Decodes a base64-encoded string back into its original byte string representation.

Parameters​

NameTypeDescription
valuet.AnyThe base64-encoded string to be converted back into bytes

Returns​

TypeDescription
t.AnyThe decoded byte string recovered from the base64 input