protobin 0.0.25__tar.gz → 0.0.26__tar.gz
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.
- {protobin-0.0.25 → protobin-0.0.26}/PKG-INFO +1 -1
- {protobin-0.0.25 → protobin-0.0.26}/protobin/protocol.py +22 -13
- {protobin-0.0.25 → protobin-0.0.26}/pyproject.toml +1 -1
- {protobin-0.0.25 → protobin-0.0.26}/tests/codec8.json +3 -3
- {protobin-0.0.25 → protobin-0.0.26}/tests/tests.py +33 -25
- {protobin-0.0.25 → protobin-0.0.26}/.gitignore +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/LICENSE.txt +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/README.md +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/protobin/__init__.py +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/protobin/errors.py +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/protobin/fields.py +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/protobin/interfaces.py +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/tests/demo.json +0 -0
- {protobin-0.0.25 → protobin-0.0.26}/tests/demo.yaml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: protobin
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.26
|
|
4
4
|
Summary: Python library for encode and decode data in protobin format
|
|
5
5
|
Project-URL: Homepage, https://github.com/drmelectronic/protobin-python
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/drmelectronic/protobin-python/issues
|
|
@@ -114,21 +114,30 @@ class Protocol:
|
|
|
114
114
|
binary = len(binary).to_bytes(self.length, 'big', signed=False) + binary + self.get_crc(binary)
|
|
115
115
|
return binary
|
|
116
116
|
|
|
117
|
-
def
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
def get_header(self, binary):
|
|
118
|
+
n = binary.find(b'=')
|
|
119
|
+
if n == -1:
|
|
120
|
+
binary = self.check_crc(binary)
|
|
121
|
+
h = binary[:1]
|
|
122
|
+
binary = binary[1:]
|
|
123
|
+
format = self.get_codec(h)
|
|
124
|
+
else:
|
|
125
|
+
if n > 4:
|
|
121
126
|
binary = self.check_crc(binary)
|
|
122
|
-
|
|
123
|
-
binary = binary[1:]
|
|
124
|
-
format = self.get_codec(h)
|
|
125
|
-
else:
|
|
127
|
+
n = binary.find(b'=')
|
|
126
128
|
if n > 4:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
h = binary[:1]
|
|
130
|
+
binary = binary[1:]
|
|
131
|
+
format = self.get_codec(h)
|
|
132
|
+
return format, binary
|
|
133
|
+
h = binary[0:n]
|
|
134
|
+
binary = binary[n + 1:]
|
|
135
|
+
format = self.get_format(h)
|
|
136
|
+
return format, binary
|
|
137
|
+
|
|
138
|
+
def decode(self, binary, codec=None):
|
|
139
|
+
if codec is None:
|
|
140
|
+
format, binary = self.get_header(binary)
|
|
132
141
|
else:
|
|
133
142
|
format = self.formats[codec]
|
|
134
143
|
if format.crc and self.crc16:
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"events8b": {"type": "array", "array": {
|
|
46
46
|
"id": {"type": "id", "bytes": 1},
|
|
47
47
|
"value": {"type": "unsigned", "bytes": 8}
|
|
48
|
-
}}
|
|
49
|
-
|
|
50
|
-
}
|
|
48
|
+
}}
|
|
49
|
+
}},
|
|
50
|
+
"#reports": {"type": "unsigned", "bytes": 1}
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"status3": {
|
|
@@ -570,31 +570,32 @@ report:
|
|
|
570
570
|
header, recv = client.decode(binary)
|
|
571
571
|
self.assertEqual(recv, {
|
|
572
572
|
'positions': [{
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
573
|
+
'time': datetime.datetime(2019, 6, 10, 5, 4, 46),
|
|
574
|
+
'priority': 1,
|
|
575
|
+
'lng': 0.0,
|
|
576
|
+
'lat': 0.0,
|
|
577
|
+
'alt': 0,
|
|
578
|
+
'angle': 0,
|
|
579
|
+
'satellites': 0,
|
|
580
|
+
'speed': 0,
|
|
581
|
+
'event_io': 1,
|
|
582
|
+
'#events': 5,
|
|
583
|
+
'events1b': [
|
|
584
|
+
{'id': 21, 'value': 3},
|
|
585
|
+
{'id': 1, 'value': 1}
|
|
586
|
+
],
|
|
587
|
+
'events2b': [
|
|
588
|
+
{'id': 66, 'value': 24079}
|
|
589
|
+
],
|
|
590
|
+
'events4b': [
|
|
591
|
+
{'id': 241, 'value': 24602}
|
|
592
|
+
],
|
|
593
|
+
'events8b': [
|
|
594
|
+
{'id': 78, 'value': 0}
|
|
595
|
+
]}
|
|
586
596
|
],
|
|
587
|
-
'
|
|
588
|
-
|
|
589
|
-
],
|
|
590
|
-
'events4b': [
|
|
591
|
-
{'id': 241, 'value': 24602}
|
|
592
|
-
],
|
|
593
|
-
'events8b': [
|
|
594
|
-
{'id': 78, 'value': 0}
|
|
595
|
-
],
|
|
596
|
-
'#reports': 1,
|
|
597
|
-
}]})
|
|
597
|
+
'#reports': 1
|
|
598
|
+
})
|
|
598
599
|
|
|
599
600
|
def test_login_keyerror(self):
|
|
600
601
|
client = Protocol(file='demo.json', server=False)
|
|
@@ -611,7 +612,7 @@ report:
|
|
|
611
612
|
self.assertEqual(data, recv)
|
|
612
613
|
|
|
613
614
|
def test_crc(self):
|
|
614
|
-
data = {'positions': [{'time': datetime.datetime(2024, 10, 19, 9, 37, 57, 555000), 'priority': 1, 'lng': -77.0155334, 'lat': -12.0613651, 'alt': 0, 'angle': 0, 'satellites': 3, 'speed': 105, 'event_io': 0, '#events': 0, 'events1b': [], 'events2b': [], 'events4b': [], 'events8b': [], '#reports': 1}
|
|
615
|
+
data = {'positions': [{'time': datetime.datetime(2024, 10, 19, 9, 37, 57, 555000), 'priority': 1, 'lng': -77.0155334, 'lat': -12.0613651, 'alt': 0, 'angle': 0, 'satellites': 3, 'speed': 105, 'event_io': 0, '#events': 0, 'events1b': [], 'events2b': [], 'events4b': [], 'events8b': []}], '#reports': 1}
|
|
615
616
|
client = Protocol(file='codec8.json')
|
|
616
617
|
binary = client.encode(data, 'report')
|
|
617
618
|
self.assertEqual(b'\x00\x00\x00\x00\x00\x00\x00!\x08\x01\x00\x00\x01\x92\xa56\xaf\xb3\x01\xd2\x18\\\xba\xf8\xcf\x94\xed\x00\x00\x00\x00\x03\x00i\x00\x00\x00\x00\x00\x00\x01\x00\x00\xa3\xe4', binary)
|
|
@@ -634,3 +635,10 @@ report:
|
|
|
634
635
|
data = {'positions': 1}
|
|
635
636
|
binary = protocol.encode(data, 'report_ack')
|
|
636
637
|
self.assertEqual(binary, b'\x00\x00\x00\x01')
|
|
638
|
+
|
|
639
|
+
def test_decode_codec8(self):
|
|
640
|
+
# binary = b'\xfe\x0f350424068858891\x00\x00\x01\x06CBF541\x04\x00\x02R\x00\x00\x00\x00\x01\x00\x00\x1e\n\x04\x00)\x11$\x100\x00R\xff\x00\x00\x00\x02'
|
|
641
|
+
binary = b'\x00\x00\x00\x00\x00\x00\x01\x11\x08\t\x00\x00\x01\x93x\xd74\xf0\x00\xd2\x15\x19\xe6\xf8\xc6\xe8\x9e\x00Z\x01b\x0e\x00\r\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd7_\xe8\x00\xd2\x15\x1b#\xf8\xc6\xfau\x00W\x00\x06\x0f\x00\x0e\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd7\x86\xf8\x00\xd2\x15\x19\xf7\xf8\xc7\x0c~\x00S\x01e\x10\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd7\xd5\x18\x00\xd2\x15\x19\xf7\xf8\xc7\x14=\x00U\x00\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd8#8\x00\xd2\x15\x19\xf7\xf8\xc7\x14=\x00U\x00\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd8qX\x00\xd2\x15\x19\xf7\xf8\xc7\x14=\x00U\x00\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd8\xb3\xc0\x00\xd2\x15\x1bU\xf8\xc7%\xe2\x00R\x01g\x10\x00\x19\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd8\xcf\x18\x00\xd2\x15\x1a\xe0\xf8\xc79\x8b\x00T\x01g\x0f\x00\x17\x00\x00\x00\x00\x00\x00\x00\x00\x01\x93x\xd8\xeeX\x00\xd2\x15\x1al\xf8\xc7K\x1f\x00Y\x00\x01\x0e\x00\x17\x00\x00\x00\x00\x00\x00\t\x00\x00\x13x'
|
|
642
|
+
client = Protocol(file='codec8.json')
|
|
643
|
+
header, recv = client.decode(binary)
|
|
644
|
+
print(header, recv)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|