protobin 0.0.9__tar.gz → 0.0.10__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.9 → protobin-0.0.10}/PKG-INFO +1 -1
- {protobin-0.0.9 → protobin-0.0.10}/protobin/fields.py +11 -8
- {protobin-0.0.9 → protobin-0.0.10}/protobin/protocol.py +2 -2
- {protobin-0.0.9 → protobin-0.0.10}/pyproject.toml +1 -1
- {protobin-0.0.9 → protobin-0.0.10}/.gitignore +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/LICENSE.txt +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/README.md +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/protobin/__init__.py +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/protobin/errors.py +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/protobin/interfaces.py +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/tests/demo.json +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/tests/demo.yaml +0 -0
- {protobin-0.0.9 → protobin-0.0.10}/tests/tests.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: protobin
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.10
|
|
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
|
|
@@ -25,11 +25,13 @@ class FieldEnum(enum.StrEnum):
|
|
|
25
25
|
|
|
26
26
|
class FieldBase:
|
|
27
27
|
bytes: int | None
|
|
28
|
-
|
|
28
|
+
keys: List[str] | None
|
|
29
|
+
key: str
|
|
29
30
|
type: FieldEnum
|
|
30
31
|
|
|
31
32
|
def __init__(self, k, js):
|
|
32
33
|
self.key = k
|
|
34
|
+
self.keys = None
|
|
33
35
|
self.type = js['type']
|
|
34
36
|
self.bytes = js.get('bytes')
|
|
35
37
|
|
|
@@ -79,7 +81,6 @@ class FieldBase:
|
|
|
79
81
|
return binary[1:binary[0] + 1], binary[binary[0] + 1:]
|
|
80
82
|
|
|
81
83
|
|
|
82
|
-
|
|
83
84
|
class FieldArray(FieldBase):
|
|
84
85
|
length: int
|
|
85
86
|
|
|
@@ -203,7 +204,9 @@ class FieldDate(FieldBase):
|
|
|
203
204
|
self.bytes = 3
|
|
204
205
|
|
|
205
206
|
def to_binary(self, val: datetime.datetime | str):
|
|
206
|
-
if
|
|
207
|
+
if val is None:
|
|
208
|
+
val = datetime.datetime(2000, 1, 1)
|
|
209
|
+
elif isinstance(val, str):
|
|
207
210
|
val = datetime.datetime.strptime(val, '%Y-%m-%d').date()
|
|
208
211
|
return bytes([
|
|
209
212
|
self.to_nible(val.day),
|
|
@@ -254,7 +257,7 @@ class FieldFlags(FieldBase):
|
|
|
254
257
|
|
|
255
258
|
def __init__(self, k, js):
|
|
256
259
|
super().__init__(k, js)
|
|
257
|
-
self.
|
|
260
|
+
self.keys = self.key.split(',')
|
|
258
261
|
self.length = len(self.key)
|
|
259
262
|
self.bytes = math.ceil(self.length / 8)
|
|
260
263
|
|
|
@@ -268,15 +271,15 @@ class FieldFlags(FieldBase):
|
|
|
268
271
|
for b in bits:
|
|
269
272
|
flags.append(b == '1')
|
|
270
273
|
val = {}
|
|
271
|
-
order = -len(self.
|
|
272
|
-
for k in self.
|
|
274
|
+
order = -len(self.keys)
|
|
275
|
+
for k in self.keys:
|
|
273
276
|
val[k] = flags[order]
|
|
274
277
|
order += 1
|
|
275
278
|
return val
|
|
276
279
|
|
|
277
280
|
def to_binary(self, data):
|
|
278
|
-
bits = '0' * (8 - (len(self.
|
|
279
|
-
for k in self.
|
|
281
|
+
bits = '0' * (8 - (len(self.keys) % 8))
|
|
282
|
+
for k in self.keys:
|
|
280
283
|
bits += '1' if data[k] else '0'
|
|
281
284
|
return int(bits, 2).to_bytes(self.bytes, 'big', signed=False)
|
|
282
285
|
|
|
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
|