Skip to main content

TagBytes

This class provides a mechanism for handling byte strings within a JSON tagging system. It identifies byte objects, encodes them into Base64-encoded ASCII strings for JSON serialization, and decodes them back into their original byte format during deserialization.

Attributes

AttributeTypeDescription
keystring = bThe unique identifier string used to tag base64-encoded byte data within a JSON structure.

Methods


check()

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

Determines if the provided value is a bytes object that can be processed by this tag.

Parameters

NameTypeDescription
valuet.AnyThe input value to verify for compatibility with byte operations

Returns

TypeDescription
boolTrue if the value is of type bytes, False otherwise

to_json()

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

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

Parameters

NameTypeDescription
valuet.AnyThe raw bytes object to be encoded for JSON storage

Returns

TypeDescription
t.AnyAn ASCII string representing the base64-encoded version of the input bytes

to_python()

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

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

Parameters

NameTypeDescription
valuet.AnyThe base64-encoded string or bytes to be converted back to a Python bytes object

Returns

TypeDescription
t.AnyThe decoded bytes object recovered from the base64 string