struct-frame 0.0.20__py3-none-any.whl → 0.0.23__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_cpp.h +42 -0
- struct_frame/boilerplate/c/struct_frame_gen.h +0 -1
- struct_frame/boilerplate/c/struct_frame_parser.h +5 -5
- struct_frame/boilerplate/c/struct_frame_types.h +2 -4
- struct_frame/c_gen.py +25 -21
- struct_frame/generate.py +16 -11
- struct_frame/ts_gen.py +19 -16
- {struct_frame-0.0.20.dist-info → struct_frame-0.0.23.dist-info}/METADATA +1 -3
- struct_frame-0.0.23.dist-info/RECORD +19 -0
- struct_frame-0.0.20.dist-info/RECORD +0 -18
- {struct_frame-0.0.20.dist-info → struct_frame-0.0.23.dist-info}/WHEEL +0 -0
- {struct_frame-0.0.20.dist-info → struct_frame-0.0.23.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
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "struct_frame_parser.h"
|
|
4
|
+
#include "struct_frame_types.h"
|
|
5
|
+
|
|
6
|
+
class StructFrameDevice : public struct_buffer {
|
|
7
|
+
public:
|
|
8
|
+
StructFrameDevice(struct_frame_config config)
|
|
9
|
+
: struct_buffer{config, nullptr, 0, 0, false, 0, LOOKING_FOR_START_BYTE, 0, {false, 0, 0}},
|
|
10
|
+
parser_result_{config, false, 0, 0, false, {0, 0}} {}
|
|
11
|
+
|
|
12
|
+
void Init() { PutArray(struct_buffer::data, struct_buffer::max_size, 0); }
|
|
13
|
+
|
|
14
|
+
void RunRx() {
|
|
15
|
+
uint8_t *buffer;
|
|
16
|
+
size_t buffer_size;
|
|
17
|
+
GetArray(buffer, buffer_size);
|
|
18
|
+
if (buffer && buffer_size) {
|
|
19
|
+
while (!parser_result_.finished) {
|
|
20
|
+
if (parse_buffer(buffer, buffer_size, &parser_result_)) {
|
|
21
|
+
if (parser_result_.valid) {
|
|
22
|
+
HandleResult();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void RunTx() { PutArray(struct_buffer::data, struct_buffer::max_size, struct_buffer::size); }
|
|
30
|
+
|
|
31
|
+
// Put Array must accept the full buffer of data and returns a pointer to either a new buffer or the same buffer
|
|
32
|
+
// that is free
|
|
33
|
+
virtual void PutArray(uint8_t *&buffer, size_t &max_length, size_t length) = 0;
|
|
34
|
+
|
|
35
|
+
// Get array, a pointer to an array and refernce to the array length is pased and mutated by this function
|
|
36
|
+
virtual void GetArray(uint8_t *&buffer, size_t &length) = 0;
|
|
37
|
+
|
|
38
|
+
virtual void HandleResult() = 0;
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
buffer_parser_result_t parser_result_;
|
|
42
|
+
};
|
|
@@ -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
|
}
|
|
@@ -65,6 +63,7 @@ static inline bool parse_char(struct_buffer *pb, uint8_t c) {
|
|
|
65
63
|
static inline bool parse_buffer(uint8_t *buffer, size_t size, buffer_parser_result_t *parser_result) {
|
|
66
64
|
enum ParserState state = LOOKING_FOR_START_BYTE;
|
|
67
65
|
parser_functions_t *parse_func_ptr;
|
|
66
|
+
parser_result->finished = false;
|
|
68
67
|
for (size_t i = parser_result->r_loc; i < size; i++) {
|
|
69
68
|
switch (state) {
|
|
70
69
|
case LOOKING_FOR_START_BYTE:
|
|
@@ -83,7 +82,6 @@ static inline bool parse_buffer(uint8_t *buffer, size_t size, buffer_parser_resu
|
|
|
83
82
|
case GETTING_PAYLOAD:
|
|
84
83
|
parser_result->msg_loc = buffer + i;
|
|
85
84
|
parser_result->r_loc = i + parser_result->msg_id_len.len;
|
|
86
|
-
parser_result->found = true;
|
|
87
85
|
if (parse_func_ptr->validate_packet(parser_result->msg_loc, &parser_result->msg_id_len)) {
|
|
88
86
|
parser_result->valid = true;
|
|
89
87
|
return true;
|
|
@@ -97,5 +95,7 @@ static inline bool parse_buffer(uint8_t *buffer, size_t size, buffer_parser_resu
|
|
|
97
95
|
break;
|
|
98
96
|
}
|
|
99
97
|
}
|
|
98
|
+
parser_result->finished = true;
|
|
99
|
+
parser_result->r_loc = 0;
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
@@ -43,7 +43,6 @@ typedef struct _struct_frame_buffer {
|
|
|
43
43
|
|
|
44
44
|
typedef struct _buffer_parser_result_t {
|
|
45
45
|
struct_frame_config config;
|
|
46
|
-
bool found;
|
|
47
46
|
bool valid;
|
|
48
47
|
uint8_t *msg_loc;
|
|
49
48
|
size_t r_loc;
|
|
@@ -56,12 +55,11 @@ typedef struct _buffer_parser_result_t {
|
|
|
56
55
|
|
|
57
56
|
#define default_parser {0, 0, 0x90}
|
|
58
57
|
|
|
59
|
-
#define zero_initialized_parser_result {default_parser, false,
|
|
58
|
+
#define zero_initialized_parser_result {default_parser, false, 0, 0, false, {0, 0}}
|
|
60
59
|
|
|
61
60
|
#define CREATE_DEFAULT_STRUCT_BUFFER(name, size) \
|
|
62
61
|
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}}
|
|
62
|
+
struct_buffer name = {default_parser, name##_buffer, size, 0, false, 0, LOOKING_FOR_START_BYTE, 0, {false, 0, 0}};
|
|
65
63
|
|
|
66
64
|
typedef struct checksum_t {
|
|
67
65
|
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 = []
|
|
@@ -309,8 +314,6 @@ def printPackages():
|
|
|
309
314
|
for key, value in packages.items():
|
|
310
315
|
print(value)
|
|
311
316
|
|
|
312
|
-
import os
|
|
313
|
-
import shutil
|
|
314
317
|
|
|
315
318
|
def generateCFileStrings(path):
|
|
316
319
|
out = {}
|
|
@@ -321,6 +324,7 @@ def generateCFileStrings(path):
|
|
|
321
324
|
|
|
322
325
|
return out
|
|
323
326
|
|
|
327
|
+
|
|
324
328
|
def generateTsFileStrings(path):
|
|
325
329
|
out = {}
|
|
326
330
|
for key, value in packages.items():
|
|
@@ -346,7 +350,7 @@ def main():
|
|
|
346
350
|
|
|
347
351
|
if (args.build_c):
|
|
348
352
|
files = generateCFileStrings(args.c_path[0])
|
|
349
|
-
|
|
353
|
+
|
|
350
354
|
if (args.build_ts):
|
|
351
355
|
files.update(generateTsFileStrings(args.ts_path[0]))
|
|
352
356
|
|
|
@@ -355,21 +359,22 @@ def main():
|
|
|
355
359
|
if dirname and not os.path.exists(dirname):
|
|
356
360
|
os.makedirs(dirname)
|
|
357
361
|
|
|
358
|
-
with open(filename
|
|
359
|
-
|
|
362
|
+
with open(filename, 'w', encoding='utf-8') as f:
|
|
363
|
+
f.write(filedata)
|
|
360
364
|
|
|
361
365
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
362
366
|
|
|
363
367
|
if (args.build_c):
|
|
364
|
-
shutil.copytree(os.path.join(dir_path,"boilerplate/c"),
|
|
365
|
-
|
|
368
|
+
shutil.copytree(os.path.join(dir_path, "boilerplate/c"),
|
|
369
|
+
args.c_path[0], dirs_exist_ok=True)
|
|
370
|
+
|
|
366
371
|
if (args.build_ts):
|
|
367
|
-
shutil.copytree(os.path.join(dir_path,"boilerplate/ts"),
|
|
368
|
-
|
|
372
|
+
shutil.copytree(os.path.join(dir_path, "boilerplate/ts"),
|
|
373
|
+
args.ts_path[0], dirs_exist_ok=True)
|
|
374
|
+
|
|
369
375
|
if args.debug:
|
|
370
376
|
printPackages()
|
|
371
377
|
print("Struct Frame successfully completed")
|
|
372
|
-
|
|
373
378
|
|
|
374
379
|
|
|
375
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.23
|
|
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,19 @@
|
|
|
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_cpp.h,sha256=gZRNmrQqmzoGkfwlGKh14dfbndkeVhnro11SNPngJng,1387
|
|
9
|
+
struct_frame/boilerplate/c/struct_frame_gen.h,sha256=rsuYGesEv1rWzSU1z6ybG-1e95RuVR7_IiR1mGLhYpQ,14
|
|
10
|
+
struct_frame/boilerplate/c/struct_frame_parser.h,sha256=5WP-0fH8BbqTeRUdzAye0Qh6gPBNHwVUocB3-gn5MOE,3005
|
|
11
|
+
struct_frame/boilerplate/c/struct_frame_types.h,sha256=5aJUQ_cbVPM9drdRfo1gmN46-PiAtICAZYrpVjmHaJA,1684
|
|
12
|
+
struct_frame/boilerplate/ts/struct_frame.ts,sha256=botKdIKVP7Bi6BJdXfIZaGAmoATnuj54LxZxc4DAWqM,2252
|
|
13
|
+
struct_frame/boilerplate/ts/struct_frame_gen.ts,sha256=pz6QTIWDTIY0rMCFiGNgp3DcfO7cKsmXrx3rj3zgN_U,164
|
|
14
|
+
struct_frame/boilerplate/ts/struct_frame_parser.ts,sha256=6eTbafomqTsX3Fvfn82rxNQMxu4PwTaPug38xw4wrhE,3523
|
|
15
|
+
struct_frame/boilerplate/ts/struct_frame_types.ts,sha256=aBtxVI2lUJKGPTtJAOpbStpS2sXSKvd4XWCIsOnaMk8,2130
|
|
16
|
+
struct_frame-0.0.23.dist-info/METADATA,sha256=hR99Tvri4v-oJ6nFuhoOo8MfsIm91zcCIeCbYO_gk14,704
|
|
17
|
+
struct_frame-0.0.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
18
|
+
struct_frame-0.0.23.dist-info/licenses/LICENSE,sha256=UjbLtGfcHCIqJg9UzEVGoNW8fyX4Ah9ZbsuAmJ_vhmk,1094
|
|
19
|
+
struct_frame-0.0.23.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=9_DTI54tjG48fP9GUzb6npRmzgynAOUJgIVFXQSlxm8,11819
|
|
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.20.dist-info/METADATA,sha256=ybLoKrdsxSTfOnAOghQzYzwnXhT9jpCzNk1l3LjYX-Q,734
|
|
16
|
-
struct_frame-0.0.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
-
struct_frame-0.0.20.dist-info/licenses/LICENSE,sha256=UjbLtGfcHCIqJg9UzEVGoNW8fyX4Ah9ZbsuAmJ_vhmk,1094
|
|
18
|
-
struct_frame-0.0.20.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|