protobin 0.0.4__tar.gz → 0.0.5__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.3
2
2
  Name: protobin
3
- Version: 0.0.4
3
+ Version: 0.0.5
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
@@ -281,18 +281,18 @@ class FieldFloat(FieldBase):
281
281
 
282
282
  def __init__(self, js):
283
283
  super().__init__(js)
284
- self.decimales = js['decimales']
284
+ self.decimals = js['decimals']
285
285
 
286
286
  def from_binary(self, binary):
287
287
  val = int.from_bytes(binary[:self.bytes], 'big', signed=True)
288
- return val / (10 ** self.decimales)
288
+ return val / (10 ** self.decimals)
289
289
 
290
290
  def to_binary(self, val):
291
- return int(round(val * (10 ** self.decimales))).to_bytes(self.bytes, 'big', signed=True)
291
+ return int(round(val * (10 ** self.decimals))).to_bytes(self.bytes, 'big', signed=True)
292
292
 
293
293
  def to_dict(self):
294
294
  d = super().to_dict()
295
- d['decimales'] = self.decimales
295
+ d['decimals'] = self.decimals
296
296
  return d
297
297
 
298
298
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.4"
7
+ version = "0.0.5"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -7,7 +7,7 @@
7
7
  {"keys": ["activo", "reintegro"], "bytes": 1, "type": "flags"},
8
8
  {"keys": ["lunes", "martes", "miercoles", "jueves", "viernes", "sabado", "domingo", "feriado"], "bytes": 1, "type": "flags"},
9
9
  {"key": "ruta", "bytes": 2, "type": "unsigned"},
10
- {"key": "tarifa", "bytes": 2, "type": "float", "decimales": 2},
10
+ {"key": "tarifa", "bytes": 2, "type": "float", "decimals": 2},
11
11
  {"key": "timestamp", "bytes": 6, "type": "datetime"}
12
12
  ],
13
13
  "command": [
@@ -45,8 +45,8 @@
45
45
  "geocerca": [
46
46
  {"key": "id", "bytes": 2, "type": "unsigned"},
47
47
  {"key": "orden", "bytes": 1, "type": "unsigned"},
48
- {"key": "longitud", "bytes": 4, "type": "float", "decimales": 6},
49
- {"key": "latitud", "bytes": 4, "type": "float", "decimales": 6},
48
+ {"key": "longitud", "bytes": 4, "type": "float", "decimals": 6},
49
+ {"key": "latitud", "bytes": 4, "type": "float", "decimals": 6},
50
50
  {"key": "radio", "bytes": 2, "type": "unsigned"},
51
51
  {"key": "ruta", "bytes": 1, "type": "unsigned"},
52
52
  {"keys": ["lado", "control", "datear", "activo"], "bytes": 1, "type": "flags"},
@@ -146,8 +146,8 @@
146
146
  "busstop": [
147
147
  {"key": "id", "bytes": 2, "type": "unsigned"},
148
148
  {"key": "orden", "bytes": 1, "type": "unsigned"},
149
- {"key": "longitud", "bytes": 4, "type": "float", "decimales": 6},
150
- {"key": "latitud", "bytes": 4, "type": "float", "decimales": 6},
149
+ {"key": "longitud", "bytes": 4, "type": "float", "decimals": 6},
150
+ {"key": "latitud", "bytes": 4, "type": "float", "decimals": 6},
151
151
  {"key": "radio", "bytes": 2, "type": "unsigned"},
152
152
  {"key": "ruta", "bytes": 1, "type": "unsigned"},
153
153
  {"keys": ["liquidar", "lado", "terminal", "activo"], "bytes": 1, "type": "flags"},
@@ -167,8 +167,8 @@
167
167
  "report": [
168
168
  {"key": "positions", "bytes": 19, "type": "array", "array": [
169
169
  {"key": "time", "bytes": 6, "type": "datetime"},
170
- {"key": "lng", "bytes": 4, "type": "float", "decimales": 6},
171
- {"key": "lat", "bytes": 4, "type": "float", "decimales": 6},
170
+ {"key": "lng", "bytes": 4, "type": "float", "decimals": 6},
171
+ {"key": "lat", "bytes": 4, "type": "float", "decimals": 6},
172
172
  {"key": "speed", "bytes": 1, "type": "unsigned"},
173
173
  {"key": "mark", "bytes": 2, "type": "unsigned"},
174
174
  {"key": "busstop", "bytes": 2, "type": "unsigned"}
@@ -99,7 +99,7 @@ class FormatTest(unittest.TestCase):
99
99
  'date': [{'key': 'test', 'bytes': 3, 'type': 'date'}],
100
100
  'datetime': [{'key': 'test', 'bytes': 6, 'type': 'datetime'}],
101
101
  'flags': [{'keys': ['f1', 'f2', 'f3', 'f4'], 'bytes': 1, 'type': 'flags'}],
102
- 'float': [{'key': 'test', 'bytes': 4, 'decimales': 6, 'type': 'float'}],
102
+ 'float': [{'key': 'test', 'bytes': 4, 'decimals': 6, 'type': 'float'}],
103
103
  'signed': [{'key': 'test', 'bytes': 2, 'type': 'signed'}],
104
104
  'string': [{'key': 'test', 'bytes': 0, 'type': 'string'}],
105
105
  'time': [{'key': 'test', 'bytes': 1, 'type': 'time'}],
@@ -122,7 +122,7 @@ class BasicTest(unittest.TestCase):
122
122
  'date': [{'key': 'test', 'bytes': 1, 'type': 'date'}],
123
123
  'datetime': [{'key': 'test', 'bytes': 1, 'type': 'datetime'}],
124
124
  'flags': [{'keys': ['f1', 'f2', 'f3', 'f4'], 'type': 'flags'}],
125
- 'float': [{'key': 'test', 'bytes': 4, 'decimales': 6, 'type': 'float'}],
125
+ 'float': [{'key': 'test', 'bytes': 4, 'decimals': 6, 'type': 'float'}],
126
126
  'signed': [{'key': 'test', 'bytes': 2, 'type': 'signed'}],
127
127
  'string': [{'key': 'test', 'bytes': 0, 'type': 'string'}],
128
128
  'time': [{'key': 'test', 'bytes': 2, 'type': 'time'}],
@@ -139,23 +139,30 @@ class BasicTest(unittest.TestCase):
139
139
  binary = self.protocol.encode(data, 'array')
140
140
  recv = self.protocol.decode(binary, 'array')
141
141
  self.assertEqual(data, recv)
142
+ data = {'test': [
143
+ {'test': 'texto2 de prueba'},
144
+ {'test': 'segunda prueba4'},
145
+ {'test': 'otra más3'},
146
+ {'test': 'y una última'}]
147
+ }
148
+ binary = self.protocol.encode(data, 'array')
149
+ recv = self.protocol.decode(binary, 'array')
150
+ self.assertEqual(data, recv)
142
151
 
143
152
  def test_bits(self):
144
153
  data = {'test': [True, False, True, False, False] * 3}
145
- print('data', data)
146
154
  binary = self.protocol.encode(data, 'bits')
147
- print('binary', binary)
148
155
  recv = self.protocol.decode(binary, 'bits')
149
- print('recv', recv)
156
+ self.assertEqual(data, recv)
157
+ data = {'test': [True, False, True, False, False] * 5}
158
+ binary = self.protocol.encode(data, 'bits')
159
+ recv = self.protocol.decode(binary, 'bits')
150
160
  self.assertEqual(data, recv)
151
161
 
152
162
  def test_bits_fixed(self):
153
163
  data = {'test': [True, False, True, False, False, True, True]}
154
- print('data', data)
155
164
  binary = self.protocol.encode(data, 'bits_fixed')
156
- print('binary', binary)
157
165
  recv = self.protocol.decode(binary, 'bits_fixed')
158
- print('recv', recv)
159
166
  self.assertEqual(data, recv)
160
167
 
161
168
  def test_bool(self):
@@ -245,9 +252,11 @@ class AdvancedTest(unittest.TestCase):
245
252
  ]})
246
253
  data = {'id': 2, 'nombre': 'Voltaje', 'valor': -20}
247
254
  binary = protocol.encode(data, 'medida')
248
- print('binary', binary)
249
255
  recv = protocol.decode(binary, 'medida')
250
- print('recv', recv)
256
+ self.assertEqual(data, recv)
257
+ data = {'id': 4, 'nombre': 'Corriente', 'valor': 240}
258
+ binary = protocol.encode(data, 'medida')
259
+ recv = protocol.decode(binary, 'medida')
251
260
  self.assertEqual(data, recv)
252
261
 
253
262
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes