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
| Attribute | Type | Description |
|---|---|---|
| key | string = b | The 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The object to be checked for compatibility with byte serialization |
Returns
| Type | Description |
|---|---|
bool | True 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The byte string to be converted into a JSON-safe format |
Returns
| Type | Description |
|---|---|
t.Any | A 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
| Name | Type | Description |
|---|---|---|
| value | t.Any | The base64-encoded string to be converted back into bytes |
Returns
| Type | Description |
|---|---|
t.Any | The decoded byte string recovered from the base64 input |