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
| Attribute | Type | Description |
|---|---|---|
| key | string = b | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The input value to verify for compatibility with byte operations |
Returns
| Type | Description |
|---|---|
bool | True 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The raw bytes object to be encoded for JSON storage |
Returns
| Type | Description |
|---|---|
t.Any | An 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The base64-encoded string or bytes to be converted back to a Python bytes object |
Returns
| Type | Description |
|---|---|
t.Any | The decoded bytes object recovered from the base64 string |