/
_support_wrappers.py
143 lines (100 loc) · 4.24 KB
/
_support_wrappers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (c) 2019 OpenCyphal
# This software is distributed under the terms of the MIT License.
"""
This module intentionally avoids importing ``nunavut_support`` at the module level to avoid dependency on
autogenerated code unless explicitly requested by the application.
"""
from typing import TypeVar, Type, Sequence, Any, Iterable, Optional, Dict
import pydsdl
T = TypeVar("T")
def serialize(obj: Any) -> Iterable[memoryview]:
"""
A wrapper over ``nunavut_support.serialize``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.serialize(obj)
def deserialize(dtype: Type[T], fragmented_serialized_representation: Sequence[memoryview]) -> Optional[T]:
"""
A wrapper over ``nunavut_support.deserialize``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.deserialize(dtype, fragmented_serialized_representation)
def get_model(class_or_instance: Any) -> pydsdl.CompositeType:
"""
A wrapper over ``nunavut_support.get_model``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.get_model(class_or_instance)
def get_class(model: pydsdl.CompositeType) -> type:
"""
A wrapper over ``nunavut_support.get_class``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.get_class(model)
def get_extent_bytes(class_or_instance: Any) -> int:
"""
A wrapper over ``nunavut_support.get_extent_bytes``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.get_extent_bytes(class_or_instance)
def get_fixed_port_id(class_or_instance: Any) -> Optional[int]:
"""
A wrapper over ``nunavut_support.get_fixed_port_id``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.get_fixed_port_id(class_or_instance)
def get_attribute(obj: Any, name: str) -> Any:
"""
A wrapper over ``nunavut_support.get_attribute``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.get_attribute(obj, name)
def set_attribute(obj: Any, name: str, value: Any) -> None:
"""
A wrapper over ``nunavut_support.set_attribute``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.set_attribute(obj, name, value)
def is_serializable(dtype: Any) -> bool:
"""
A wrapper over ``nunavut_support.is_serializable``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.is_serializable(dtype)
def is_message_type(dtype: Any) -> bool:
"""
A wrapper over ``nunavut_support.is_message_type``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.is_message_type(dtype)
def is_service_type(dtype: Any) -> bool:
"""
A wrapper over ``nunavut_support.is_service_type``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.is_service_type(dtype)
def to_builtin(obj: object) -> Dict[str, Any]:
"""
A wrapper over ``nunavut_support.to_builtin``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.to_builtin(obj)
def update_from_builtin(destination: T, source: Any) -> T:
"""
A wrapper over ``nunavut_support.update_from_builtin``.
The ``nunavut_support`` module will be generated automatically if it is not importable.
"""
import nunavut_support
return nunavut_support.update_from_builtin(destination, source)