protobin 0.0.43__tar.gz → 0.0.45__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: protobin
3
- Version: 0.0.43
3
+ Version: 0.0.45
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
@@ -121,7 +121,11 @@ class ArrayField(FieldBase):
121
121
  data = {}
122
122
  for f in self.fields:
123
123
  val, binary = f.decode(binary)
124
- data[f.key] = val
124
+ if f.keys:
125
+ for k, v in val.items():
126
+ data[k] = v
127
+ else:
128
+ data[f.key] = val
125
129
  lista.append(data)
126
130
  return lista, binary
127
131
 
@@ -214,7 +218,7 @@ class CharField(FieldBase):
214
218
 
215
219
  def to_binary(self, val):
216
220
  if val is None:
217
- return bytes([0])
221
+ val = ''
218
222
  encoded = val[:self.bytes].encode('utf')
219
223
  if self.bytes == 1 and len(encoded) > 1:
220
224
  raise ValueError(f'{self} of one byte is possible to encode a utf-8 character')
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.43"
7
+ version = "0.0.45"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -202,6 +202,12 @@ class BasicTest(unittest.TestCase):
202
202
  h, recv = self.protocol.decode(binary)
203
203
  self.assertEqual(data, recv)
204
204
 
205
+ def test_char_none(self):
206
+ data = {'test': None}
207
+ binary = self.protocol.encode(data, 'char')
208
+ h, recv = self.protocol.decode(binary)
209
+ self.assertEqual({'test': ' '}, recv)
210
+
205
211
  def test_char_utf(self):
206
212
  data = {'test': 'ñ'}
207
213
  binary = self.protocol.encode(data, 'char')
@@ -851,3 +857,46 @@ report:
851
857
  self.assertEqual(binary, rasp)
852
858
  h, recv = client.decode(binary)
853
859
  print(recv)
860
+
861
+ def test_flag_array(self):
862
+ codec = {
863
+ "formats":{
864
+ "flag_array": {
865
+ "header": "F",
866
+ "fields": {
867
+ "id": {"bytes": 2, "type": "unsigned"},
868
+ "lado,control,datear,activo": {"type": "flags"}
869
+ }
870
+ }
871
+ }
872
+ }
873
+ data = {'lado': False, 'activo': True, 'datear': True, 'control': True, 'id': 1}
874
+ client = Protocol(js=codec, server=None)
875
+ binary = client.encode(data, 'flag_array')
876
+ h, recv = client.decode(binary)
877
+ self.assertEqual(data, recv)
878
+ codec = {
879
+ "formats":{
880
+ "flag_array": {
881
+ "header": "F",
882
+ "fields": {
883
+ "items": {
884
+ "type": "array",
885
+ "array": {
886
+ "id": {"bytes": 2, "type": "unsigned"},
887
+ "lado,control,datear,activo": {"type": "flags"}
888
+ }
889
+ }
890
+ }
891
+ }
892
+ }
893
+ }
894
+ data = {'items': [
895
+ {'lado': False, 'activo': True, 'datear': True, 'control': True, 'id': 1},
896
+ {'lado': False, 'activo': True, 'datear': False, 'control': True, 'id': 2},
897
+ {'lado': False, 'activo': True, 'datear': False, 'control': False, 'id': 3}
898
+ ]}
899
+ client = Protocol(js=codec, server=None)
900
+ binary = client.encode(data, 'flag_array')
901
+ h, recv = client.decode(binary)
902
+ self.assertEqual(data, recv)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes