File tree Expand file tree Collapse file tree
src/query_farm_server_base Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import base64
12import json
23from collections .abc import Callable , Generator
34from dataclasses import dataclass
@@ -77,6 +78,35 @@ def endpoint(
7778 )
7879
7980
81+ def dict_to_msgpack_data_uri (data : dict [str , Any ]) -> str :
82+ """
83+ Convert a dictionary to a data URI with MessagePack encoding.
84+ """
85+ msgpack_bytes = msgpack .packb (data , use_bin_type = True )
86+ assert msgpack_bytes
87+
88+ # Encode as base64 for inclusion in the data URI
89+ b64_encoded = base64 .b64encode (msgpack_bytes ).decode ("ascii" )
90+
91+ # Construct the data URI
92+ return f"data:application/msgpack;base64,{ b64_encoded } "
93+
94+
95+ def dict_to_msgpack_duckdb_call_data_uri (data : dict [str , Any ]) -> str :
96+ """
97+ Convert a dictionary to a data URI with MessagePack encoding for
98+ duckdb function calls.
99+ """
100+ msgpack_bytes = msgpack .packb (data , use_bin_type = True )
101+ assert msgpack_bytes
102+
103+ # Encode as base64 for inclusion in the data URI
104+ b64_encoded = base64 .b64encode (msgpack_bytes ).decode ("ascii" )
105+
106+ # Construct the data URI
107+ return f"data:application/x-msgpack-duckdb-function-call;base64,{ b64_encoded } "
108+
109+
80110def decode_ticket_model (source : flight .Ticket , model_cls : type [AnyModel ]) -> AnyModel :
81111 decode_fields : set [str ] = set ()
82112 for name , field in model_cls .model_fields .items ():
You can’t perform that action at this time.
0 commit comments