struct-frame 0.0.19__py3-none-any.whl → 0.0.22__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of struct-frame might be problematic. Click here for more details.
- struct_frame/__init__.py +2 -1
- struct_frame/base.py +8 -3
- struct_frame/boilerplate/c/struct_frame.h +48 -53
- struct_frame/boilerplate/c/struct_frame_gen.h +0 -1
- struct_frame/boilerplate/c/struct_frame_parser.h +2 -4
- struct_frame/boilerplate/c/struct_frame_types.h +1 -2
- struct_frame/c_gen.py +25 -21
- struct_frame/generate.py +29 -11
- struct_frame/ts_gen.py +19 -16
- {struct_frame-0.0.19.dist-info → struct_frame-0.0.22.dist-info}/METADATA +1 -3
- struct_frame-0.0.22.dist-info/RECORD +18 -0
- struct_frame-0.0.19.dist-info/RECORD +0 -18
- {struct_frame-0.0.19.dist-info → struct_frame-0.0.22.dist-info}/WHEEL +0 -0
- {struct_frame-0.0.19.dist-info → struct_frame-0.0.22.dist-info}/licenses/LICENSE +0 -0
struct_frame/__init__.py
CHANGED
|
@@ -5,4 +5,5 @@ from .ts_gen import FileTsGen
|
|
|
5
5
|
|
|
6
6
|
from .generate import main
|
|
7
7
|
|
|
8
|
-
__all__ = ["main", "FileCGen", "FileTsGen", "version",
|
|
8
|
+
__all__ = ["main", "FileCGen", "FileTsGen", "version",
|
|
9
|
+
"NamingStyleC", "CamelToSnakeCase", "pascalCase"]
|
struct_frame/base.py
CHANGED
|
@@ -3,6 +3,7 @@ import re
|
|
|
3
3
|
|
|
4
4
|
version = "0.0.1"
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
class NamingStyle:
|
|
7
8
|
def enum_name(self, name):
|
|
8
9
|
return "_%s" % (name)
|
|
@@ -52,7 +53,7 @@ class NamingStyleC(NamingStyle):
|
|
|
52
53
|
return self.underscore(name)
|
|
53
54
|
|
|
54
55
|
def enum_entry(self, name):
|
|
55
|
-
return
|
|
56
|
+
return name.upper()
|
|
56
57
|
|
|
57
58
|
def func_name(self, name):
|
|
58
59
|
return self.underscore(name)
|
|
@@ -66,15 +67,19 @@ class NamingStyleC(NamingStyle):
|
|
|
66
67
|
word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
|
|
67
68
|
word = word.replace("-", "_")
|
|
68
69
|
return word.lower()
|
|
69
|
-
|
|
70
|
+
|
|
71
|
+
|
|
70
72
|
def camelCase(st):
|
|
71
73
|
output = ''.join(x for x in st.title() if x.isalnum())
|
|
72
74
|
return output[0].lower() + output[1:]
|
|
73
75
|
|
|
76
|
+
|
|
74
77
|
def pascalCase(st):
|
|
75
78
|
return ''.join(x for x in st.title() if x.isalnum())
|
|
76
79
|
|
|
80
|
+
|
|
77
81
|
pattern = re.compile(r'(?<!^)(?=[A-Z])')
|
|
78
82
|
|
|
83
|
+
|
|
79
84
|
def CamelToSnakeCase(data):
|
|
80
|
-
return pattern.sub('_', data).lower()
|
|
85
|
+
return pattern.sub('_', data).lower()
|
|
@@ -4,51 +4,50 @@
|
|
|
4
4
|
#include "string.h"
|
|
5
5
|
#include "struct_frame_types.h"
|
|
6
6
|
|
|
7
|
-
static inline struct checksum_t fletcher_checksum_calculation(uint8_t *buffer, uint8_t data_length)
|
|
8
|
-
{
|
|
7
|
+
static inline struct checksum_t fletcher_checksum_calculation(uint8_t *buffer, uint8_t data_length) {
|
|
9
8
|
checksum_t checksum;
|
|
10
9
|
|
|
11
|
-
for (int i = 0; i < data_length; i++)
|
|
12
|
-
{
|
|
10
|
+
for (int i = 0; i < data_length; i++) {
|
|
13
11
|
checksum.byte1 += buffer[i];
|
|
14
12
|
checksum.byte2 += checksum.byte1;
|
|
15
13
|
}
|
|
16
14
|
return checksum;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
static inline
|
|
20
|
-
{
|
|
17
|
+
static inline bool msg_encode(struct_buffer *buffer, void *msg_buffer, uint8_t msg_id, uint8_t size) {
|
|
18
|
+
if (buffer->in_progress) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
buffer->in_progress = true;
|
|
22
|
+
|
|
21
23
|
buffer->data[buffer->size++] = buffer->config.start_byte;
|
|
22
24
|
buffer->crc_start_loc = buffer->size;
|
|
23
25
|
buffer->data[buffer->size++] = msg_id;
|
|
24
26
|
|
|
25
|
-
if (buffer->config.has_len)
|
|
26
|
-
{
|
|
27
|
+
if (buffer->config.has_len) {
|
|
27
28
|
buffer->data[buffer->size++] = size;
|
|
28
29
|
}
|
|
29
30
|
memcpy(buffer->data + buffer->size, (uint8_t *)msg_buffer, size);
|
|
30
31
|
buffer->size += size;
|
|
31
|
-
if (buffer->config.has_crc)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
buffer->crc_start_loc - buffer->size);
|
|
32
|
+
if (buffer->config.has_crc) {
|
|
33
|
+
checksum_t crc =
|
|
34
|
+
fletcher_checksum_calculation(buffer->data + buffer->crc_start_loc, buffer->crc_start_loc - buffer->size);
|
|
35
35
|
buffer->data[buffer->size++] = crc.byte1;
|
|
36
36
|
buffer->data[buffer->size++] = crc.byte2;
|
|
37
37
|
}
|
|
38
|
+
buffer->in_progress = false;
|
|
39
|
+
return true;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
static inline void *msg_reserve(struct_buffer *buffer, uint8_t msg_id, uint8_t size)
|
|
41
|
-
{
|
|
42
|
-
if (buffer->in_progress)
|
|
43
|
-
{
|
|
42
|
+
static inline void *msg_reserve(struct_buffer *buffer, uint8_t msg_id, uint8_t size) {
|
|
43
|
+
if (buffer->in_progress) {
|
|
44
44
|
return 0;
|
|
45
45
|
}
|
|
46
46
|
buffer->in_progress = true;
|
|
47
47
|
buffer->data[buffer->size++] = buffer->config.start_byte;
|
|
48
48
|
|
|
49
49
|
buffer->data[buffer->size++] = msg_id;
|
|
50
|
-
if (buffer->config.has_len)
|
|
51
|
-
{
|
|
50
|
+
if (buffer->config.has_len) {
|
|
52
51
|
buffer->data[buffer->size++] = size;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -58,46 +57,42 @@ static inline void *msg_reserve(struct_buffer *buffer, uint8_t msg_id, uint8_t s
|
|
|
58
57
|
return out;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
static inline
|
|
62
|
-
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
static inline bool msg_finish(struct_buffer *buffer) {
|
|
61
|
+
if (buffer->in_progress == false) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (buffer->config.has_crc) {
|
|
65
|
+
checksum_t crc =
|
|
66
|
+
fletcher_checksum_calculation(buffer->data + buffer->crc_start_loc, buffer->crc_start_loc - buffer->size);
|
|
67
67
|
buffer->data[buffer->size++] = crc.byte1;
|
|
68
68
|
buffer->data[buffer->size++] = crc.byte2;
|
|
69
69
|
}
|
|
70
70
|
buffer->in_progress = false;
|
|
71
|
+
return true;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
#define MESSAGE_HELPER(funcname, name, msg_size, msg_id)
|
|
74
|
-
static inline
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
name msg = *(name *)(
|
|
92
|
-
return msg;
|
|
93
|
-
}
|
|
94
|
-
static inline name funcname##_get_from_buffer_result(buffer_parser_result_t result) \
|
|
95
|
-
{ \
|
|
96
|
-
name msg = *(name *)(result.msg_loc); \
|
|
97
|
-
return msg; \
|
|
98
|
-
} \
|
|
74
|
+
#define MESSAGE_HELPER(funcname, name, msg_size, msg_id) \
|
|
75
|
+
static inline bool funcname##_encode(struct_buffer *buffer, name *name##_obj) { \
|
|
76
|
+
return msg_encode(buffer, name##_obj, msg_id, msg_size); \
|
|
77
|
+
} \
|
|
78
|
+
static inline bool funcname##_reserve(struct_buffer *buffer, name **msg) { \
|
|
79
|
+
void *ptr = msg_reserve(buffer, msg_id, msg_size); \
|
|
80
|
+
if (ptr) { \
|
|
81
|
+
*msg = (name *)ptr; \
|
|
82
|
+
return true; \
|
|
83
|
+
} \
|
|
84
|
+
return false; \
|
|
85
|
+
} \
|
|
86
|
+
static inline bool funcname##_finish(struct_buffer *buffer) { return msg_finish(buffer); } \
|
|
87
|
+
static inline name funcname##_get(struct_buffer *buffer) { \
|
|
88
|
+
name msg = *(name *)(buffer->data); \
|
|
89
|
+
return msg; \
|
|
90
|
+
} \
|
|
91
|
+
static inline name funcname##_get_from_buffer_result(buffer_parser_result_t result) { \
|
|
92
|
+
name msg = *(name *)(result.msg_loc); \
|
|
93
|
+
return msg; \
|
|
94
|
+
} \
|
|
99
95
|
static inline name *funcname##_get_ref(struct_buffer *buffer) { return (name *)(buffer->data); } \
|
|
100
|
-
static inline name *funcname##_get_ref_from_buffer_result(buffer_parser_result_t result)
|
|
101
|
-
|
|
102
|
-
return (name *)(result.msg_loc); \
|
|
96
|
+
static inline name *funcname##_get_ref_from_buffer_result(buffer_parser_result_t result) { \
|
|
97
|
+
return (name *)(result.msg_loc); \
|
|
103
98
|
}
|
|
@@ -17,11 +17,9 @@ static inline bool parse_default_format_char_for_len_id(msg_id_len_t *msg_id_len
|
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
parser_functions_t default_parser_functions = {parse_default_format_char_for_len_id,
|
|
21
|
-
parse_default_format_validate};
|
|
20
|
+
parser_functions_t default_parser_functions = {parse_default_format_char_for_len_id, parse_default_format_validate};
|
|
22
21
|
|
|
23
|
-
static inline parser_functions_t *parse_char_for_start_byte(const struct_frame_config config,
|
|
24
|
-
const uint8_t c) {
|
|
22
|
+
static inline parser_functions_t *parse_char_for_start_byte(const struct_frame_config config, const uint8_t c) {
|
|
25
23
|
if (config.start_byte == c) {
|
|
26
24
|
return &default_parser_functions;
|
|
27
25
|
}
|
|
@@ -60,8 +60,7 @@ typedef struct _buffer_parser_result_t {
|
|
|
60
60
|
|
|
61
61
|
#define CREATE_DEFAULT_STRUCT_BUFFER(name, size) \
|
|
62
62
|
uint8_t name##_buffer[size]; \
|
|
63
|
-
struct_buffer name = {
|
|
64
|
-
default_parser, name##_buffer, size, 0, false, 0, LOOKING_FOR_START_BYTE, 0, {false, 0, 0}}
|
|
63
|
+
struct_buffer name = {default_parser, name##_buffer, size, 0, false, 0, LOOKING_FOR_START_BYTE, 0, {false, 0, 0}};
|
|
65
64
|
|
|
66
65
|
typedef struct checksum_t {
|
|
67
66
|
uint8_t byte1;
|
struct_frame/c_gen.py
CHANGED
|
@@ -14,7 +14,10 @@ c_types = {"uint8": "uint8_t",
|
|
|
14
14
|
"int32": "int32_t",
|
|
15
15
|
"bool": "bool",
|
|
16
16
|
"float": "float",
|
|
17
|
-
"double": "double"
|
|
17
|
+
"double": "double",
|
|
18
|
+
"uint64": 'uint64_t',
|
|
19
|
+
"int64": 'int64_t',
|
|
20
|
+
}
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
class EnumCGen():
|
|
@@ -26,7 +29,7 @@ class EnumCGen():
|
|
|
26
29
|
if leading_comment:
|
|
27
30
|
for c in leading_comment:
|
|
28
31
|
result = '%s\n' % c
|
|
29
|
-
|
|
32
|
+
|
|
30
33
|
enumName = '%s%s' % (pascalCase(field.package), field.name)
|
|
31
34
|
result += 'typedef enum %s' % (enumName)
|
|
32
35
|
|
|
@@ -46,8 +49,9 @@ class EnumCGen():
|
|
|
46
49
|
# last enum member should not end with a comma
|
|
47
50
|
comma = ""
|
|
48
51
|
|
|
49
|
-
enum_value = " %s_%s = %d%s" % (CamelToSnakeCase(
|
|
50
|
-
|
|
52
|
+
enum_value = " %s_%s = %d%s" % (CamelToSnakeCase(
|
|
53
|
+
field.name).upper(), StyleC.enum_entry(d), field.data[d][0], comma)
|
|
54
|
+
|
|
51
55
|
enum_values.append(enum_value)
|
|
52
56
|
|
|
53
57
|
result += '\n'.join(enum_values)
|
|
@@ -65,7 +69,7 @@ class FieldCGen():
|
|
|
65
69
|
result = ''
|
|
66
70
|
|
|
67
71
|
var_name = field.name
|
|
68
|
-
type_name = field.fieldType
|
|
72
|
+
type_name = field.fieldType
|
|
69
73
|
if type_name in c_types:
|
|
70
74
|
type_name = c_types[type_name]
|
|
71
75
|
else:
|
|
@@ -73,7 +77,6 @@ class FieldCGen():
|
|
|
73
77
|
if field.isEnum:
|
|
74
78
|
type_name = '%s_t' % type_name
|
|
75
79
|
|
|
76
|
-
|
|
77
80
|
result += ' %s %s%s;' % (type_name, var_name, "")
|
|
78
81
|
|
|
79
82
|
leading_comment = field.comments
|
|
@@ -94,8 +97,7 @@ class MessageCGen():
|
|
|
94
97
|
for c in msg.comments:
|
|
95
98
|
result = '%s\n' % c
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
structName = '%s%s' % (pascalCase(msg.package), msg.name.title())
|
|
100
|
+
structName = '%s%s' % (pascalCase(msg.package), msg.name)
|
|
99
101
|
result += 'typedef struct %s {' % structName
|
|
100
102
|
|
|
101
103
|
result += '\n'
|
|
@@ -107,25 +109,26 @@ class MessageCGen():
|
|
|
107
109
|
result += ' char dummy_field;'
|
|
108
110
|
else:
|
|
109
111
|
size = msg.size
|
|
110
|
-
|
|
111
|
-
result += '\n'.join([FieldCGen.generate(f)
|
|
112
|
+
|
|
113
|
+
result += '\n'.join([FieldCGen.generate(f)
|
|
114
|
+
for key, f in msg.fields.items()])
|
|
112
115
|
result += '\n}'
|
|
113
116
|
result += ' %s;\n\n' % structName
|
|
114
|
-
|
|
115
|
-
defineName = '%s_%s' % (CamelToSnakeCase(
|
|
116
|
-
|
|
117
|
+
|
|
118
|
+
defineName = '%s_%s' % (CamelToSnakeCase(
|
|
119
|
+
msg.package).upper(), CamelToSnakeCase(msg.name).upper())
|
|
120
|
+
result += '#define %s_MAX_SIZE %d\n' % (defineName, size)
|
|
117
121
|
|
|
118
122
|
if msg.id:
|
|
119
123
|
result += '#define %s_MSG_ID %d\n' % (defineName, msg.id)
|
|
120
124
|
|
|
121
|
-
|
|
122
125
|
funcName = defineName.lower()
|
|
123
126
|
if msg.id:
|
|
124
127
|
result += 'MESSAGE_HELPER(%s, %s, %d, %d);\n\n' % (funcName, structName,
|
|
125
|
-
|
|
128
|
+
size, msg.id)
|
|
126
129
|
|
|
127
130
|
return result + '\n'
|
|
128
|
-
|
|
131
|
+
|
|
129
132
|
@staticmethod
|
|
130
133
|
def get_initializer(msg, null_init):
|
|
131
134
|
if not msg.fields:
|
|
@@ -148,7 +151,7 @@ class FileCGen():
|
|
|
148
151
|
|
|
149
152
|
yield '#include "struct_frame.h"\n'
|
|
150
153
|
|
|
151
|
-
#include additional header files if available in the future
|
|
154
|
+
# include additional header files if available in the future
|
|
152
155
|
|
|
153
156
|
if package.enums:
|
|
154
157
|
yield '/* Enum definitions */\n'
|
|
@@ -164,7 +167,7 @@ class FileCGen():
|
|
|
164
167
|
yield '\n'
|
|
165
168
|
|
|
166
169
|
# Add default initializers if needed
|
|
167
|
-
#if package.messages:
|
|
170
|
+
# if package.messages:
|
|
168
171
|
# yield '/* Initializer values for message structs */\n'
|
|
169
172
|
# for key, msg in package.messages.items():
|
|
170
173
|
# identifier = '%s_%s_init_default' % (package.name, StyleC.struct_name(msg.name))
|
|
@@ -177,9 +180,10 @@ class FileCGen():
|
|
|
177
180
|
if package.messages:
|
|
178
181
|
yield 'uint8_t get_message_length(uint8_t msg_id){\n switch (msg_id)\n {\n'
|
|
179
182
|
for key, msg in package.sortedMessages().items():
|
|
180
|
-
name = '%s_%s' % (CamelToSnakeCase(
|
|
181
|
-
|
|
183
|
+
name = '%s_%s' % (CamelToSnakeCase(
|
|
184
|
+
msg.package).upper(), CamelToSnakeCase(msg.name).upper())
|
|
185
|
+
if msg.id:
|
|
186
|
+
yield ' case %s_MSG_ID: return %s_MAX_SIZE;\n' % (name, name)
|
|
182
187
|
|
|
183
188
|
yield ' default: break;\n } return 0;\n}'
|
|
184
189
|
yield '\n'
|
|
185
|
-
|
struct_frame/generate.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# kate: replace-tabs on; indent-width 4;
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
5
7
|
from struct_frame import FileCGen
|
|
6
8
|
from struct_frame import FileTsGen
|
|
7
9
|
from proto_schema_parser.parser import Parser
|
|
@@ -21,7 +23,9 @@ default_types = {
|
|
|
21
23
|
"int32": {"size": 4},
|
|
22
24
|
"bool": {"size": 1},
|
|
23
25
|
"float": {"size": 4},
|
|
24
|
-
"double": {"size": 8}
|
|
26
|
+
"double": {"size": 8},
|
|
27
|
+
"int64": {"size": 8},
|
|
28
|
+
"uint64": {"size": 8}
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
|
|
@@ -241,6 +245,7 @@ class Package:
|
|
|
241
245
|
output = output + value.__str__() + "\n"
|
|
242
246
|
return output
|
|
243
247
|
|
|
248
|
+
|
|
244
249
|
packages = {}
|
|
245
250
|
processed_file = []
|
|
246
251
|
required_file = []
|
|
@@ -251,6 +256,8 @@ parser = argparse.ArgumentParser(
|
|
|
251
256
|
|
|
252
257
|
parser.add_argument('filename')
|
|
253
258
|
parser.add_argument('--debug', action='store_true')
|
|
259
|
+
parser.add_argument('--build_c', action='store_true')
|
|
260
|
+
parser.add_argument('--build_ts', action='store_true')
|
|
254
261
|
parser.add_argument('--c_path', nargs=1, type=str, default=['c/'])
|
|
255
262
|
parser.add_argument('--ts_path', nargs=1, type=str, default=['ts/'])
|
|
256
263
|
|
|
@@ -307,8 +314,6 @@ def printPackages():
|
|
|
307
314
|
for key, value in packages.items():
|
|
308
315
|
print(value)
|
|
309
316
|
|
|
310
|
-
import os
|
|
311
|
-
import shutil
|
|
312
317
|
|
|
313
318
|
def generateCFileStrings(path):
|
|
314
319
|
out = {}
|
|
@@ -319,6 +324,7 @@ def generateCFileStrings(path):
|
|
|
319
324
|
|
|
320
325
|
return out
|
|
321
326
|
|
|
327
|
+
|
|
322
328
|
def generateTsFileStrings(path):
|
|
323
329
|
out = {}
|
|
324
330
|
for key, value in packages.items():
|
|
@@ -332,31 +338,43 @@ def main():
|
|
|
332
338
|
args = parser.parse_args()
|
|
333
339
|
parseFile(args.filename)
|
|
334
340
|
|
|
341
|
+
if (not args.build_c and not args.build_ts):
|
|
342
|
+
print("Select at least one build argument")
|
|
343
|
+
return
|
|
344
|
+
|
|
335
345
|
try:
|
|
336
346
|
validatePackages()
|
|
337
347
|
except RecursionError as err:
|
|
338
348
|
print(
|
|
339
349
|
f'Recursion Error. Messages most likely have a cyclical dependancy. Check Message: {recErrCurrentMessage} and Field: {recErrCurrentField}')
|
|
340
350
|
|
|
341
|
-
|
|
342
|
-
|
|
351
|
+
if (args.build_c):
|
|
352
|
+
files = generateCFileStrings(args.c_path[0])
|
|
353
|
+
|
|
354
|
+
if (args.build_ts):
|
|
355
|
+
files.update(generateTsFileStrings(args.ts_path[0]))
|
|
343
356
|
|
|
344
357
|
for filename, filedata in files.items():
|
|
345
358
|
dirname = os.path.dirname(filename)
|
|
346
359
|
if dirname and not os.path.exists(dirname):
|
|
347
360
|
os.makedirs(dirname)
|
|
348
361
|
|
|
349
|
-
with open(filename
|
|
350
|
-
|
|
362
|
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
363
|
+
f.write(filedata)
|
|
351
364
|
|
|
352
365
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
366
|
+
|
|
367
|
+
if (args.build_c):
|
|
368
|
+
shutil.copytree(os.path.join(dir_path, "boilerplate/c"),
|
|
369
|
+
args.c_path[0], dirs_exist_ok=True)
|
|
370
|
+
|
|
371
|
+
if (args.build_ts):
|
|
372
|
+
shutil.copytree(os.path.join(dir_path, "boilerplate/ts"),
|
|
373
|
+
args.ts_path[0], dirs_exist_ok=True)
|
|
374
|
+
|
|
356
375
|
if args.debug:
|
|
357
376
|
printPackages()
|
|
358
377
|
print("Struct Frame successfully completed")
|
|
359
|
-
|
|
360
378
|
|
|
361
379
|
|
|
362
380
|
if __name__ == '__main__':
|
struct_frame/ts_gen.py
CHANGED
|
@@ -7,19 +7,20 @@ import time
|
|
|
7
7
|
StyleC = NamingStyleC()
|
|
8
8
|
|
|
9
9
|
ts_types = {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
10
|
+
"int8": 'Int8',
|
|
11
|
+
"uint8": 'UInt8',
|
|
12
|
+
"int16": 'Int16LE',
|
|
13
|
+
"uint16": 'UInt16LE',
|
|
14
14
|
"bool": 'Boolean8',
|
|
15
15
|
"double": 'Float64LE',
|
|
16
16
|
"float": 'Float32LE',
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
17
|
+
"int32": 'Int32LE',
|
|
18
|
+
"uint32": 'UInt32LE',
|
|
19
|
+
"uint64": 'BigInt64LE',
|
|
20
|
+
"int64": 'BigUInt64LE',
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
class EnumTsGen():
|
|
24
25
|
@staticmethod
|
|
25
26
|
def generate(field, packageName):
|
|
@@ -29,7 +30,8 @@ class EnumTsGen():
|
|
|
29
30
|
for c in leading_comment:
|
|
30
31
|
result = '%s\n' % c
|
|
31
32
|
|
|
32
|
-
result += 'export enum %s%s' % (packageName,
|
|
33
|
+
result += 'export enum %s%s' % (packageName,
|
|
34
|
+
StyleC.enum_name(field.name))
|
|
33
35
|
|
|
34
36
|
result += ' {\n'
|
|
35
37
|
|
|
@@ -49,7 +51,7 @@ class EnumTsGen():
|
|
|
49
51
|
|
|
50
52
|
enum_value = " %s = %d%s" % (
|
|
51
53
|
StyleC.enum_entry(d), field.data[d][0], comma)
|
|
52
|
-
|
|
54
|
+
|
|
53
55
|
enum_values.append(enum_value)
|
|
54
56
|
|
|
55
57
|
result += '\n'.join(enum_values)
|
|
@@ -65,7 +67,7 @@ class FieldTsGen():
|
|
|
65
67
|
isEnum = False
|
|
66
68
|
# isEnum = field.pbtype in ('ENUM', 'UENUM')
|
|
67
69
|
var_name = StyleC.var_name(field.name)
|
|
68
|
-
type_name = field.fieldType
|
|
70
|
+
type_name = field.fieldType
|
|
69
71
|
if type_name in ts_types:
|
|
70
72
|
type_name = ts_types[type_name]
|
|
71
73
|
else:
|
|
@@ -98,7 +100,7 @@ class MessageTsGen():
|
|
|
98
100
|
if leading_comment:
|
|
99
101
|
for c in msg.comments:
|
|
100
102
|
result = '%s\n' % c
|
|
101
|
-
|
|
103
|
+
|
|
102
104
|
struct_name = '%s_%s' % (packageName, StyleC.type_name(msg.name))
|
|
103
105
|
result += 'export const %s = new typed_struct.Struct(\'%s\') ' % (
|
|
104
106
|
struct_name, struct_name)
|
|
@@ -113,7 +115,8 @@ class MessageTsGen():
|
|
|
113
115
|
else:
|
|
114
116
|
size = msg.size
|
|
115
117
|
|
|
116
|
-
result += '\n'.join([FieldTsGen.generate(f, packageName)
|
|
118
|
+
result += '\n'.join([FieldTsGen.generate(f, packageName)
|
|
119
|
+
for key, f in msg.fields.items()])
|
|
117
120
|
result += '\n .compile();\n\n'
|
|
118
121
|
|
|
119
122
|
result += 'export const %s_max_size = %d;\n' % (struct_name, size)
|
|
@@ -147,7 +150,7 @@ class MessageTsGen():
|
|
|
147
150
|
for field in msg.fields:
|
|
148
151
|
parts.append(field.get_initializer(null_init))
|
|
149
152
|
return '{' + ', '.join(parts) + '}'
|
|
150
|
-
|
|
153
|
+
|
|
151
154
|
|
|
152
155
|
class FileTsGen():
|
|
153
156
|
@staticmethod
|
|
@@ -163,8 +166,8 @@ class FileTsGen():
|
|
|
163
166
|
|
|
164
167
|
yield "import { msg_encode, msg_reserve, msg_finish } from './struct_frame';\n\n"
|
|
165
168
|
|
|
166
|
-
#include additional header files here if available in the future
|
|
167
|
-
|
|
169
|
+
# include additional header files here if available in the future
|
|
170
|
+
|
|
168
171
|
if package.enums:
|
|
169
172
|
yield '/* Enum definitions */\n'
|
|
170
173
|
for key, enum in package.enums.items():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: struct-frame
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.22
|
|
4
4
|
Summary: A framework for serializing data with headers
|
|
5
5
|
Project-URL: Homepage, https://github.com/mylonics/struct-frame
|
|
6
6
|
Project-URL: Issues, https://github.com/mylonics/struct-frame/issues
|
|
@@ -26,5 +26,3 @@ node index.js
|
|
|
26
26
|
npx tsc --project tsconfig.json; node index.js
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
usage python -m struct_frame
|
|
30
|
-
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
struct_frame/__init__.py,sha256=HnmRU0-0so_x2zmRtex4weF1XPd11SE73iBHn0hcKE4,283
|
|
2
|
+
struct_frame/__main__.py,sha256=tIybnBeFHvwiwVhodVOSnxhne5AX_80mtXBx4rneSB4,143
|
|
3
|
+
struct_frame/base.py,sha256=1Z_0vMkwz0X8r2hIVLv5yuhwwD929LwNMzVKBqFxxac,2012
|
|
4
|
+
struct_frame/c_gen.py,sha256=dQw52Zgec38O471KaHuYkRyehcxfjmSOpvhppExgB1c,5969
|
|
5
|
+
struct_frame/generate.py,sha256=UkZEZtKfTEmC0lEeInL7F4amCYFx1-bXPg23382rV-Y,11903
|
|
6
|
+
struct_frame/ts_gen.py,sha256=9arnjhgQZqT4F2aTKyFQrHNpn7u-fqX3B-g_17sxIFE,6137
|
|
7
|
+
struct_frame/boilerplate/c/struct_frame.h,sha256=vou8iXsV_4dQBlZRuMNOr1RnuXD1bUJUR4A3dH_uvwM,4564
|
|
8
|
+
struct_frame/boilerplate/c/struct_frame_gen.h,sha256=rsuYGesEv1rWzSU1z6ybG-1e95RuVR7_IiR1mGLhYpQ,14
|
|
9
|
+
struct_frame/boilerplate/c/struct_frame_parser.h,sha256=EhNccWFZlhd6BxdVkCnMC431qr-1RdXwYLLgK82Q43M,2943
|
|
10
|
+
struct_frame/boilerplate/c/struct_frame_types.h,sha256=XxJmjqa1cmMnlcJVnsEOa5ObRbrEKWUw8PC1sbnF620,1707
|
|
11
|
+
struct_frame/boilerplate/ts/struct_frame.ts,sha256=botKdIKVP7Bi6BJdXfIZaGAmoATnuj54LxZxc4DAWqM,2252
|
|
12
|
+
struct_frame/boilerplate/ts/struct_frame_gen.ts,sha256=pz6QTIWDTIY0rMCFiGNgp3DcfO7cKsmXrx3rj3zgN_U,164
|
|
13
|
+
struct_frame/boilerplate/ts/struct_frame_parser.ts,sha256=6eTbafomqTsX3Fvfn82rxNQMxu4PwTaPug38xw4wrhE,3523
|
|
14
|
+
struct_frame/boilerplate/ts/struct_frame_types.ts,sha256=aBtxVI2lUJKGPTtJAOpbStpS2sXSKvd4XWCIsOnaMk8,2130
|
|
15
|
+
struct_frame-0.0.22.dist-info/METADATA,sha256=tjR1RGqYlt8ZinZYjTL0JHI9YpYzCLI9zmw1WAeOnjw,704
|
|
16
|
+
struct_frame-0.0.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
struct_frame-0.0.22.dist-info/licenses/LICENSE,sha256=UjbLtGfcHCIqJg9UzEVGoNW8fyX4Ah9ZbsuAmJ_vhmk,1094
|
|
18
|
+
struct_frame-0.0.22.dist-info/RECORD,,
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
struct_frame/__init__.py,sha256=t_GBVV-CeYA4Yupfu-pH5922nisafAOZLsyyfrJtD0c,269
|
|
2
|
-
struct_frame/__main__.py,sha256=tIybnBeFHvwiwVhodVOSnxhne5AX_80mtXBx4rneSB4,143
|
|
3
|
-
struct_frame/base.py,sha256=Sx1hwOjpmbhArPldw4jYibvd7UMRtfkSO_P0lu9NqZA,2021
|
|
4
|
-
struct_frame/c_gen.py,sha256=_XC96txPtH0ukbrMSyYegVb5GwV5ADEEDd6yY3Hg3vU,5848
|
|
5
|
-
struct_frame/generate.py,sha256=pH8o8Bj49q71O_po6CDdtFIMbwR3jrIUJ3GnzCXGcew,11459
|
|
6
|
-
struct_frame/ts_gen.py,sha256=b_mx5IwemcWB70082iHSGOAPzqcnnglXB-fEk4Q2uLM,6123
|
|
7
|
-
struct_frame/boilerplate/c/struct_frame.h,sha256=Y0V39aqXfR-eTSNe6f1hdc55GXHXBADBK2kbNrxCo-k,4909
|
|
8
|
-
struct_frame/boilerplate/c/struct_frame_gen.h,sha256=MdXFYOO6E7IN4DM5EaEMXXowZb4auv8UeyQBprkqx68,43
|
|
9
|
-
struct_frame/boilerplate/c/struct_frame_parser.h,sha256=A38zoqaAxh4cw4rG7zzF7FFQ9qnfqP2w41cpn2dO2CA,3052
|
|
10
|
-
struct_frame/boilerplate/c/struct_frame_types.h,sha256=e67BvA1kAg_OnjnktUv1fAtLB0nn7FzPVhIPaque5Ts,1740
|
|
11
|
-
struct_frame/boilerplate/ts/struct_frame.ts,sha256=botKdIKVP7Bi6BJdXfIZaGAmoATnuj54LxZxc4DAWqM,2252
|
|
12
|
-
struct_frame/boilerplate/ts/struct_frame_gen.ts,sha256=pz6QTIWDTIY0rMCFiGNgp3DcfO7cKsmXrx3rj3zgN_U,164
|
|
13
|
-
struct_frame/boilerplate/ts/struct_frame_parser.ts,sha256=6eTbafomqTsX3Fvfn82rxNQMxu4PwTaPug38xw4wrhE,3523
|
|
14
|
-
struct_frame/boilerplate/ts/struct_frame_types.ts,sha256=aBtxVI2lUJKGPTtJAOpbStpS2sXSKvd4XWCIsOnaMk8,2130
|
|
15
|
-
struct_frame-0.0.19.dist-info/METADATA,sha256=w9tHnq6xtnhCMlKUaInbwL9QQsKKwKXeKUZX784cj_0,734
|
|
16
|
-
struct_frame-0.0.19.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
-
struct_frame-0.0.19.dist-info/licenses/LICENSE,sha256=UjbLtGfcHCIqJg9UzEVGoNW8fyX4Ah9ZbsuAmJ_vhmk,1094
|
|
18
|
-
struct_frame-0.0.19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|