ctrlX Data Layer API for Python  3.3.0
The ctrlX Data Layer API allows access to the ctrlX Data Layer with Python
converter.py
1 """
2 Class Converter
3 """
4 import ctypes
5 from enum import Enum
6 
7 import ctrlxdatalayer
8 import ctrlxdatalayer.clib_converter
9 from ctrlxdatalayer.variant import Result, Variant
10 
11 C_DLR_CONVERTER = ctypes.c_void_p
12 
13 
14 class C_DLR_SCHEMA(Enum):
15  """
16  Type of Converter
17  """
18  METADATA = 0
19  REFLECTION = 1
20  MEMORY = 2
21  MEMORY_MAP = 3
22  TOKEN = 4
23  PROBLEM = 5
24  DIAGNOSIS = 6
25 
26 
27 class Converter:
28  """
29  Converter interface
30  """
31  __slots__ = ['__converter']
32 
33  def __init__(self, c_converter: C_DLR_CONVERTER):
34  """
35  generate converter
36  """
37  self.__converter__converter = c_converter
38 
39  def get_handle(self):
40  """
41  handle value of Converter:
42 
43  """
44  return self.__converter__converter
45 
46  def converter_generate_json_simple(self, data: Variant, indent_step: int):
47  """
48  This function generate a JSON string out of a Variant witch have a simple data type
49  @param[in] data Variant which contains data with simple data type
50  @param[in] indentStep Indentation length for json string
51  @returns tuple (Result, Variant)
52  @return <Result>, status of function call,
53  @return <Variant>, Generated JSON as Variant (string)
54  """
55  json = Variant()
56  result = Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_converterGenerateJsonSimple(
57  self.__converter__converter, data.get_handle(), json.get_handle(), indent_step))
58  return result, json
59 
60  def converter_generate_json_complex(self, data: Variant, ty: Variant, indent_step: int):
61  """
62  This function generate a JSON string out of a Variant with complex type (flatbuffers) and the metadata of this data
63  @param[in] data Variant which contains data of complex data type (flatbuffers) if data is empty (VariantType::UNKNOWN) type is converted to json schema
64  @param[in] type Variant which contains type of data (Variant with flatbuffers BFBS)
65  @param[in] indentStep Indentation length for json string
66  @returns tuple (Result, Variant)
67  @return <Result>, status of function call,
68  @return <Variant>, Generated JSON as Variant (string)
69  """
70  json = Variant()
71  result = Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_converterGenerateJsonComplex(
72  self.__converter__converter, data.get_handle(), ty.get_handle(), json.get_handle(), indent_step))
73  return result, json
74 
75  def parse_json_simple(self, json: str):
76  """
77  This function generates a Variant out of a JSON string containing the (simple) data
78  @param[in] json Data of the Variant as a json string
79  @returns tuple (Result, Variant, Variant)
80  @return <Result>, status of function call,
81  @return <Variant>, Variant which contains the data
82  @return <Variant>, Error as Variant (string)
83  """
84  b_json = json.encode('utf-8')
85  data = Variant()
86  err = Variant()
87  result = Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_converterParseJsonSimple(
88  self.__converter__converter, b_json, data.get_handle(), err.get_handle()))
89  return result, data, err
90 
91  def parse_json_complex(self, json: str, ty: Variant):
92  """
93  This function generates a Variant out of a JSON string containing the (complex) data
94  @param[in] json Data of the Variant as a json string
95  @param[in] type Variant which contains type of data (Variant with bfbs flatbuffer content)
96  @returns tuple (Result, Variant, Variant)
97  @return <Result>, status of function call,
98  @return <Variant>, Variant which contains the data
99  @return <Variant>, Error as Variant (string)
100  """
101  b_json = json.encode('utf-8')
102  data = Variant()
103  err = Variant()
104  result = Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_converterParseJsonComplex(
105  self.__converter__converter, b_json, ty.get_handle(), data.get_handle(), err.get_handle()))
106  return result, data, err
107 
108  def get_schema(self, schema: C_DLR_SCHEMA):
109  """
110  This function returns the type (schema)
111  @param[in] schema Requested schema
112  @returns tuple (Result, Variant)
113  @return <Result>, status of function call,
114  @return <Variant>, Variant which contains the type (schema)
115  """
116  data = Variant()
117  result = Result(ctrlxdatalayer.clib.libcomm_datalayer.DLR_converterGetSchema(
118  self.__converter__converter, schema.value, data.get_handle()))
119  return result, data
def converter_generate_json_simple(self, Variant data, int indent_step)
This function generate a JSON string out of a Variant witch have a simple data type.
Definition: converter.py:54
def converter_generate_json_complex(self, Variant data, Variant ty, int indent_step)
This function generate a JSON string out of a Variant with complex type (flatbuffers) and the metadat...
Definition: converter.py:69
def __init__(self, C_DLR_CONVERTER c_converter)
generate converter
Definition: converter.py:36
def parse_json_simple(self, str json)
This function generates a Variant out of a JSON string containing the (simple) data.
Definition: converter.py:83
def get_handle(self)
handle value of Converter:
Definition: converter.py:43
def get_schema(self, C_DLR_SCHEMA schema)
This function returns the type (schema)
Definition: converter.py:115
def parse_json_complex(self, str json, Variant ty)
This function generates a Variant out of a JSON string containing the (complex) data.
Definition: converter.py:100
Variant is a container for a many types of data.
Definition: variant.py:150