feat/#63 - cleverswarm unidirectional command
This commit is contained in:
@@ -128,6 +128,11 @@ class DataMessageFactory:
|
||||
package, class_name, method = fq_method_name.rsplit(".", 2)
|
||||
headers = {"Content-Type": ["application/octet-stream"], "Return-Address": [swarm_id]}
|
||||
trace_info = {}
|
||||
body = python_type_to_json(args).encode(encoding="utf-8") if args else b""
|
||||
print(
|
||||
f"Creating RPC message for method: {fq_method_name}, args: {args} body: {body.decode('utf-8') if body else 'None'}"
|
||||
)
|
||||
|
||||
return DataMessage(
|
||||
DataMessageMagicByte.RPC_REQUEST.value,
|
||||
self.generate_snowflake_id(),
|
||||
@@ -136,7 +141,7 @@ class DataMessageFactory:
|
||||
method,
|
||||
headers,
|
||||
trace_info,
|
||||
python_type_to_json(args) if args else b"",
|
||||
body,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -195,13 +200,13 @@ class DataMessageFactory:
|
||||
header_length = 1 + len(id_bytes) + len(prolog)
|
||||
prolog_len = header_length.to_bytes(2, byteorder="big")
|
||||
msg_length = 2 + header_length + len(message.base64body())
|
||||
with BytesIO(bytearray(msg_length)) as baos:
|
||||
baos.write(prolog_len)
|
||||
baos.write(DataMessageMagicByte.HTTP_REQUEST.value.encode("utf-8"))
|
||||
baos.write(id_bytes)
|
||||
baos.write(prolog)
|
||||
baos.write(message.base64body())
|
||||
return baos.getvalue()
|
||||
baos = BytesIO(bytearray(msg_length))
|
||||
baos.write(prolog_len)
|
||||
baos.write(message.magic().encode("utf-8"))
|
||||
baos.write(id_bytes)
|
||||
baos.write(prolog)
|
||||
baos.write(message.base64body())
|
||||
return baos.getvalue()
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(input_bytes: bytes) -> DataMessage:
|
||||
@@ -214,7 +219,7 @@ class DataMessageFactory:
|
||||
metadata = input_bytes[2 : prolog_len + 2].decode()
|
||||
|
||||
pattern = re.compile(
|
||||
f"{DataMessageMagicByte.HTTP_REQUEST.value}"
|
||||
r"([AR])"
|
||||
r"([0-9A-Fa-f]+)\|"
|
||||
r"m=([^|]*)\|"
|
||||
r"d=([^|]*)\|"
|
||||
@@ -230,19 +235,19 @@ class DataMessageFactory:
|
||||
f"Input string [{metadata}] does not match pattern: {pattern.pattern}"
|
||||
)
|
||||
|
||||
id_str = match.group(1)
|
||||
method = match.group(2)
|
||||
domain = match.group(3)
|
||||
path = match.group(4)
|
||||
headers_str = match.group(5)
|
||||
trace_info_str = match.group(6)
|
||||
id_str = match.group(2)
|
||||
method = match.group(3)
|
||||
domain = match.group(4)
|
||||
path = match.group(5)
|
||||
headers_str = match.group(6)
|
||||
trace_info_str = match.group(7)
|
||||
body_b64 = input_bytes[prolog_len + 2 :]
|
||||
|
||||
headers = parse_map_list_string(headers_str)
|
||||
trace_info = parse_map_string(trace_info_str)
|
||||
|
||||
return DataMessage(
|
||||
DataMessageMagicByte.HTTP_REQUEST.value,
|
||||
match.group(1), # Magic byte (R for RPC, A for HTTP)
|
||||
SnowflakeId.from_hex(id_str),
|
||||
method,
|
||||
domain,
|
||||
|
||||
Reference in New Issue
Block a user