in statefun-sdk-python/statefun/messages.py [0:0]
def message_builder(target_typename: str, target_id: str, **kwargs) -> Message:
"""
Build a Message that can be sent to any other function.
:param target_typename: The TypeName represented as a string of the form <namespace>/<name> of the
target function.
:param target_id: The id of the target function
:param kwargs: This specify the value type to attach to this message. The following arguments are supported:
int_value=<an int>,
float_value=<a float>
long_value=<a signed 64 bit integer>
str_value=<str>
double_value=<double>
bool_value=<bool>
...
value=<arbitrary value>, value_type=<a StateFun Type for this value>
:return: A Message object, that can be sent.
"""
if len(kwargs) == 2:
value, value_type = kwargs["value"], kwargs["value_type"]
elif len(kwargs) == 1:
# expecting: <type>_value : value
# for example one of the following:
# int_value=1
# str_value="hello world"
# long_value= 5511
type_keyword, value = next(iter(kwargs.items()))
value_type = PRIMITIVE_GETTERS.get(type_keyword)
else:
raise TypeError(f"Wrong number of value keywords given: {kwargs}, there must be exactly one of:"
f"\nint_value=.."
f"\nfloat_value.."
f"\netc'"
f"\nor:"
f"\nvalue=.. ,value_type=.. ")
if value is None:
raise ValueError("value can not be missing")
if not value_type:
raise ValueError(
"Could not deduce the value type, please specify the type explicitly. via passing: value=<the value>, "
"value_type=<the type>")
typed_value = to_typed_value(type=value_type, value=value)
return Message(target_typename=target_typename, target_id=target_id, typed_value=typed_value)