protobin 0.0.45__tar.gz → 0.0.46__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.45 → protobin-0.0.46}/PKG-INFO +1 -1
- {protobin-0.0.45 → protobin-0.0.46}/protobin/fields.py +10 -6
- {protobin-0.0.45 → protobin-0.0.46}/pyproject.toml +1 -1
- {protobin-0.0.45 → protobin-0.0.46}/tests/tests.py +22 -4
- {protobin-0.0.45 → protobin-0.0.46}/.gitignore +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/LICENSE.txt +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/README.md +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/protobin/__init__.py +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/protobin/errors.py +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/protobin/interfaces.py +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/protobin/protocol.py +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/protobin/singleton.py +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/tests/codec8.json +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/tests/demo.json +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/tests/demo.yaml +0 -0
- {protobin-0.0.45 → protobin-0.0.46}/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.46
|
|
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
|
|
@@ -159,11 +159,13 @@ class BitsField(FieldBase):
|
|
|
159
159
|
return b'\x00'
|
|
160
160
|
binary = b''
|
|
161
161
|
if len(val) % 8:
|
|
162
|
-
|
|
162
|
+
final = '0' * (8 - (len(val) % 8))
|
|
163
163
|
else:
|
|
164
|
-
|
|
164
|
+
final = ''
|
|
165
|
+
bits = ''
|
|
165
166
|
for b in val:
|
|
166
167
|
bits += '1' if b else '0'
|
|
168
|
+
bits += final
|
|
167
169
|
bts = int(len(bits) / 8)
|
|
168
170
|
if not self.length:
|
|
169
171
|
binary += len(val).to_bytes(1, 'big', signed=False)
|
|
@@ -173,10 +175,12 @@ class BitsField(FieldBase):
|
|
|
173
175
|
def from_binary_bits(self, binary, length):
|
|
174
176
|
numero = int.from_bytes(binary, 'big', signed=False)
|
|
175
177
|
bits = bin(numero)[2:]
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
val =
|
|
178
|
+
max_length = (length // 8) * 8 + (8 if (length % 8) else 0)
|
|
179
|
+
if len(bits) < max_length:
|
|
180
|
+
bits = '0' * (max_length - len(bits)) + bits
|
|
181
|
+
val = []
|
|
182
|
+
for i in range(length):
|
|
183
|
+
val.append(bits[i] == '1')
|
|
180
184
|
return val
|
|
181
185
|
|
|
182
186
|
|
|
@@ -177,6 +177,26 @@ class BasicTest(unittest.TestCase):
|
|
|
177
177
|
binary = self.protocol.encode(data, 'bits')
|
|
178
178
|
h, recv = self.protocol.decode(binary)
|
|
179
179
|
self.assertEqual(data, recv)
|
|
180
|
+
data = {'test': [True, False]}
|
|
181
|
+
binary = self.protocol.encode(data, 'bits')
|
|
182
|
+
h, recv = self.protocol.decode(binary)
|
|
183
|
+
self.assertEqual(data, recv)
|
|
184
|
+
|
|
185
|
+
def test_bits_false(self):
|
|
186
|
+
data = {'test': [False, False]}
|
|
187
|
+
binary = self.protocol.encode(data, 'bits')
|
|
188
|
+
h, recv = self.protocol.decode(binary)
|
|
189
|
+
self.assertEqual(data, recv)
|
|
190
|
+
|
|
191
|
+
def test_bits_false2(self):
|
|
192
|
+
data = {'test': [False, True]}
|
|
193
|
+
binary = self.protocol.encode(data, 'bits')
|
|
194
|
+
h, recv = self.protocol.decode(binary)
|
|
195
|
+
self.assertEqual(data, recv)
|
|
196
|
+
data = {'test': [False, True, False, False, False, False, False, False, False, False, False, False, False, False]}
|
|
197
|
+
binary = self.protocol.encode(data, 'bits')
|
|
198
|
+
h, recv = self.protocol.decode(binary)
|
|
199
|
+
self.assertEqual(data, recv)
|
|
180
200
|
|
|
181
201
|
def test_bits_fixed(self):
|
|
182
202
|
data = {'test': [True, False, True, False, False, True, True]}
|
|
@@ -210,10 +230,8 @@ class BasicTest(unittest.TestCase):
|
|
|
210
230
|
|
|
211
231
|
def test_char_utf(self):
|
|
212
232
|
data = {'test': 'ñ'}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
h, recv = self.protocol.decode(binary)
|
|
216
|
-
self.assertEqual(data, recv)
|
|
233
|
+
with self.assertRaises(ValueError):
|
|
234
|
+
self.protocol.encode(data, 'char')
|
|
217
235
|
|
|
218
236
|
def test_char2(self):
|
|
219
237
|
data = {'test': 'FA', 'prueba': 'DO'}
|
|
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
|