Source code for koapy.backend.daishin_cybos_plus.proxy.CybosPlusProxyServiceMessageUtils
import os
import subprocess
[docs]def AssignPrimitive(message, value):
if value is None:
pass
elif isinstance(value, str):
message.string_value = value
elif isinstance(value, int):
message.long_value = value
elif isinstance(value, bool):
message.bool_value = value
elif isinstance(value, float):
message.float_value = value
elif isinstance(value, list):
for item in value:
AssignPrimitive(message.list_value.values.add(), item)
elif isinstance(value, tuple):
for item in value:
AssignPrimitive(message.tuple_value.values.add(), item)
else:
raise TypeError
return message
[docs]def Protoc():
proto_filename = "CybosPlusProxyService.proto"
proto_filedir = os.path.dirname(os.path.realpath(__file__))
project_dir = os.path.realpath(os.path.join(proto_filedir, "../../.."))
proto_path = project_dir
python_out = project_dir
grpc_python_out = python_out
proto_filepath = os.path.join(proto_filedir, proto_filename)
cmd = [
"python",
"-m",
"grpc_tools.protoc",
"--proto_path=%s" % proto_path,
"--python_out=%s" % python_out,
"--grpc_python_out=%s" % grpc_python_out,
proto_filepath,
]
_ = subprocess.run(cmd, cwd=project_dir, check=True)
if __name__ == "__main__":
Protoc()