Files
sdk/python/blyss/serializer.py
Neil Movva 7740f75ec2 [BLY-64] Python Spiral v1, and docs
Python client: use spiral v1, add basic docs
Unify client versions at 0.2.0
Add min rustc version to all crates
2023-08-29 13:19:27 -07:00

24 lines
648 B
Python

"""Serialization
INTERNAL
Methods to serialize and deserialize data for storage in Blyss.
"""
from typing import Optional, Union, Any
import json
from . import varint
# Set of acceptable object types for client payload.
# Essentially, any JSONable type or raw bytes.
ClientPayloadType = Union[bytes, str, list[Any], dict[Any, Any]]
def wrap_key_val(key: bytes, value: bytes) -> bytes:
"""
Wraps a key and value into a single bytes sequence, following Blyss "kv-item" spec.
"""
key_len_varint = varint.encode(len(key))
value_len_varint = varint.encode(len(value))
return key_len_varint + key + value_len_varint + value