def __kv_map_to_bytes(kv_map): ctx = BytesSerializationContext() # Sorting the map elements to create chunks deterministically, but this is not mandatory for importing the chunk for key, value in sorted(kv_map.items()): ctx.write_varuint(len(key)) ctx.write_bytes(key) ctx.write_varuint(len(value)) ctx.write_bytes(value) return ctx.getbytes()