protobin 0.0.32__tar.gz → 0.0.34__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.32 → protobin-0.0.34}/PKG-INFO +1 -1
- {protobin-0.0.32 → protobin-0.0.34}/protobin/fields.py +2 -2
- {protobin-0.0.32 → protobin-0.0.34}/pyproject.toml +1 -1
- {protobin-0.0.32 → protobin-0.0.34}/tests/tests.py +20 -0
- {protobin-0.0.32 → protobin-0.0.34}/.gitignore +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/LICENSE.txt +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/README.md +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/protobin/__init__.py +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/protobin/errors.py +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/protobin/interfaces.py +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/protobin/protocol.py +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/protobin/singleton.py +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/tests/codec8.json +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/tests/demo.json +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/tests/demo.yaml +0 -0
- {protobin-0.0.32 → protobin-0.0.34}/tests/teltonika.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: protobin
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.34
|
|
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
|
|
@@ -207,7 +207,7 @@ class CharField(FieldBase):
|
|
|
207
207
|
|
|
208
208
|
def __init__(self, k, js):
|
|
209
209
|
super().__init__(k, js)
|
|
210
|
-
self.bytes = 1
|
|
210
|
+
self.bytes = js.get('bytes', 1)
|
|
211
211
|
|
|
212
212
|
def __repr__(self):
|
|
213
213
|
return f'CharField<key: {self.key}>'
|
|
@@ -215,7 +215,7 @@ class CharField(FieldBase):
|
|
|
215
215
|
def to_binary(self, val):
|
|
216
216
|
if val is None:
|
|
217
217
|
return bytes([0])
|
|
218
|
-
return val.encode('utf')
|
|
218
|
+
return (val + ' '*self.bytes)[:self.bytes].encode('utf')
|
|
219
219
|
|
|
220
220
|
def from_binary(self, binary):
|
|
221
221
|
val = int.from_bytes(binary[:self.bytes], 'big', signed=False)
|
|
@@ -91,6 +91,13 @@ class BasicTest(unittest.TestCase):
|
|
|
91
91
|
"header": "C",
|
|
92
92
|
"fields": {'test': {'bytes': 1, 'type': 'char'}}
|
|
93
93
|
},
|
|
94
|
+
'char2': {
|
|
95
|
+
"header": "C2",
|
|
96
|
+
"fields": {
|
|
97
|
+
'test': {'bytes': 2, 'type': 'char'},
|
|
98
|
+
'prueba': {'bytes': 2, 'type': 'char'}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
94
101
|
'date': {
|
|
95
102
|
"header": "D",
|
|
96
103
|
"fields": {'test': {'bytes': 1, 'type': 'date'}}
|
|
@@ -191,6 +198,19 @@ class BasicTest(unittest.TestCase):
|
|
|
191
198
|
h, recv = self.protocol.decode(binary)
|
|
192
199
|
self.assertEqual(data, recv)
|
|
193
200
|
|
|
201
|
+
def test_char2(self):
|
|
202
|
+
data = {'test': 'FA', 'prueba': 'DO'}
|
|
203
|
+
binary = self.protocol.encode(data, 'char2')
|
|
204
|
+
h, recv = self.protocol.decode(binary)
|
|
205
|
+
self.assertEqual(data, recv)
|
|
206
|
+
data = {'test': '', 'prueba': 'F'}
|
|
207
|
+
binary = self.protocol.encode(data, 'char2')
|
|
208
|
+
print(binary)
|
|
209
|
+
h, recv = self.protocol.decode(binary)
|
|
210
|
+
data_corregida = {'test': ' ', 'prueba': 'F '}
|
|
211
|
+
self.assertEqual(data_corregida, recv)
|
|
212
|
+
print(recv)
|
|
213
|
+
|
|
194
214
|
def test_date(self):
|
|
195
215
|
data = {'test': datetime.date(2024, 9, 13)}
|
|
196
216
|
binary = self.protocol.encode(data, 'date')
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|