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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: protobin
3
- Version: 0.0.32
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)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "protobin"
7
- version = "0.0.32"
7
+ version = "0.0.34"
8
8
  authors = [
9
9
  { name="Daniel Robles", email="drm.electronic@gmail.com" },
10
10
  ]
@@ -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