protobin 0.0.2__tar.gz → 0.0.3__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.3/PKG-INFO +119 -0
- protobin-0.0.3/README.md +82 -0
- {protobin-0.0.2 → protobin-0.0.3}/protobin/fields.py +5 -3
- {protobin-0.0.2 → protobin-0.0.3}/pyproject.toml +1 -1
- {protobin-0.0.2 → protobin-0.0.3}/tests/tests.py +17 -6
- protobin-0.0.2/PKG-INFO +0 -51
- protobin-0.0.2/README.md +0 -14
- protobin-0.0.2/tests/test_data.py +0 -2
- {protobin-0.0.2 → protobin-0.0.3}/.gitignore +0 -0
- {protobin-0.0.2 → protobin-0.0.3}/LICENSE.txt +0 -0
- {protobin-0.0.2 → protobin-0.0.3}/protobin/__init__.py +0 -0
- {protobin-0.0.2 → protobin-0.0.3}/protobin/errors.py +0 -0
- {protobin-0.0.2 → protobin-0.0.3}/protobin/protocol.py +0 -0
- {protobin-0.0.2 → protobin-0.0.3}/tests/demo.json +0 -0
protobin-0.0.3/PKG-INFO
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: protobin
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: Python library for encode and decode data in protobin format
|
|
5
|
+
Project-URL: Homepage, https://github.com/drmelectronic/protobin-python
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/drmelectronic/protobin-python/issues
|
|
7
|
+
Author-email: Daniel Robles <drm.electronic@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) [Año] [Tu Nombre]
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE. 1
|
|
29
|
+
1. en.wikipedia.org
|
|
30
|
+
en.wikipedia.org
|
|
31
|
+
License-File: LICENSE.txt
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Requires-Python: >=3.9
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# protobin
|
|
39
|
+
|
|
40
|
+
**protobin** es una biblioteca Python diseñada para facilitar la interacción con el formato de transferencia de datos Protobin en modo binario. Esta biblioteca proporciona una interfaz sencilla y eficiente para:
|
|
41
|
+
|
|
42
|
+
* **Serializar** objetos Python en datos Protobin.
|
|
43
|
+
* **Deserializar** datos Protobin en objetos Python.
|
|
44
|
+
* **Validar** la integridad de los datos Protobin.
|
|
45
|
+
|
|
46
|
+
## Instalación
|
|
47
|
+
|
|
48
|
+
Para instalar `protobin`, puedes utilizar pip:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install protobin
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Cómo empezar
|
|
55
|
+
|
|
56
|
+
### Primeros Pasos
|
|
57
|
+
Declare un protocolo de la siguiente forma:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from protobin import Protocol
|
|
61
|
+
protocol = Protocol(js={'medida': [
|
|
62
|
+
{'key': 'id', 'bytes': 1, 'type': 'unsigned'},
|
|
63
|
+
{'key': 'nombre', 'type': 'string'},
|
|
64
|
+
{'key': 'valor', 'bytes': 2, 'type': 'signed'}
|
|
65
|
+
]})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
luego cree la variable que desea transmitir como un diccionario de python, codiféquela, decodifíquela, y compruebe que la información se recuperó correctamente
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
data = {'id': 2, 'nombre': 'Voltaje', 'valor': -20}
|
|
72
|
+
binary = protocol.encode(data, 'medida')
|
|
73
|
+
print('binary', binary)
|
|
74
|
+
recv = protocol.decode(binary, 'medida')
|
|
75
|
+
print('recv', recv)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Archivo Json
|
|
79
|
+
|
|
80
|
+
El protocolo se declara en un archivo *.json o un objeto dict en python.
|
|
81
|
+
Éste contiene un diccionario donde cada clave del diccionario es el identificador de un formato.
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"formato1": [{}, {}, {}],
|
|
86
|
+
"formato2": [{}, {}]
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Cada formato se declara como una lista de campos, y cada campo es representado por un diccionario, que debe tener un **key** para identificar el dato que se almacenará en esa posición, también debe tener un **type** que define el tipo de dato que se guardará y opcionalmente **bytes** o **length** para definir la cantidad de espacio o datos que se guardarán.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Tipos de Datos
|
|
94
|
+
|
|
95
|
+
**array** : Sirve para declarar listas de objetos, requiere el campo **array* que contiene un formato completo.
|
|
96
|
+
|
|
97
|
+
**bits** : Sirve para declarar una lista de valores booleanos como un arreglo de bits en la cantidad necesaria de bytes. Es opcional el campo **length** si se quiere fijar una cantidad de elementos y usar un byte menos en su codificación.
|
|
98
|
+
|
|
99
|
+
**bool** : Sirve para declarar un único valor booleano en un byte. No requiere campos adicionales, ocupa 1 byte.
|
|
100
|
+
|
|
101
|
+
**char** : Sirve para declarar un único valor booleano en un byte. No requiere campos adicionales, ocupa 1 byte.
|
|
102
|
+
|
|
103
|
+
**date** : Sirve para declarar un valor datetime.date. No requiere campos adicionales, ocupa 3 bytes.
|
|
104
|
+
|
|
105
|
+
**datetime** : Sirve para declarar un valor datetime.datetime con presicion de segundos. No requiere campos adicionales, ocupa 6 bytes.
|
|
106
|
+
|
|
107
|
+
**flags** : Sirve para declarar una lista de keys cuyos valores sean booleanos y representarlos en un arreglo de bits. No requiere campos adicionales.
|
|
108
|
+
|
|
109
|
+
**float** : Sirve para declarar un valor numérico con una precisión fija de decimales. Requiere el campo **bytes** y **decimales**, tamaño variable.
|
|
110
|
+
|
|
111
|
+
**signed** : Sirve para declarar un valor entero positivo. Requiere el campo **bytes**, tamaño variable.
|
|
112
|
+
|
|
113
|
+
**string** : Sirve para declarar un texto. Es opcional el campo **bytes**, tamaño variable.
|
|
114
|
+
|
|
115
|
+
**time** : Sirve para declarar un valor datetime.time con presicion de minutos. No requiere campos adicionales, ocupa 2 bytes.
|
|
116
|
+
|
|
117
|
+
**timestamp** : Sirve para declarar un valor datetime.datetime con presicion de microsegundos. No requiere campos adicionales, ocupa 8 bytes.
|
|
118
|
+
|
|
119
|
+
**unsigned** : Sirve para declarar un valor entero. Requiere el campo **bytes**, tamaño variable.
|
protobin-0.0.3/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# protobin
|
|
2
|
+
|
|
3
|
+
**protobin** es una biblioteca Python diseñada para facilitar la interacción con el formato de transferencia de datos Protobin en modo binario. Esta biblioteca proporciona una interfaz sencilla y eficiente para:
|
|
4
|
+
|
|
5
|
+
* **Serializar** objetos Python en datos Protobin.
|
|
6
|
+
* **Deserializar** datos Protobin en objetos Python.
|
|
7
|
+
* **Validar** la integridad de los datos Protobin.
|
|
8
|
+
|
|
9
|
+
## Instalación
|
|
10
|
+
|
|
11
|
+
Para instalar `protobin`, puedes utilizar pip:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install protobin
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Cómo empezar
|
|
18
|
+
|
|
19
|
+
### Primeros Pasos
|
|
20
|
+
Declare un protocolo de la siguiente forma:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from protobin import Protocol
|
|
24
|
+
protocol = Protocol(js={'medida': [
|
|
25
|
+
{'key': 'id', 'bytes': 1, 'type': 'unsigned'},
|
|
26
|
+
{'key': 'nombre', 'type': 'string'},
|
|
27
|
+
{'key': 'valor', 'bytes': 2, 'type': 'signed'}
|
|
28
|
+
]})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
luego cree la variable que desea transmitir como un diccionario de python, codiféquela, decodifíquela, y compruebe que la información se recuperó correctamente
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
data = {'id': 2, 'nombre': 'Voltaje', 'valor': -20}
|
|
35
|
+
binary = protocol.encode(data, 'medida')
|
|
36
|
+
print('binary', binary)
|
|
37
|
+
recv = protocol.decode(binary, 'medida')
|
|
38
|
+
print('recv', recv)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Archivo Json
|
|
42
|
+
|
|
43
|
+
El protocolo se declara en un archivo *.json o un objeto dict en python.
|
|
44
|
+
Éste contiene un diccionario donde cada clave del diccionario es el identificador de un formato.
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"formato1": [{}, {}, {}],
|
|
49
|
+
"formato2": [{}, {}]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Cada formato se declara como una lista de campos, y cada campo es representado por un diccionario, que debe tener un **key** para identificar el dato que se almacenará en esa posición, también debe tener un **type** que define el tipo de dato que se guardará y opcionalmente **bytes** o **length** para definir la cantidad de espacio o datos que se guardarán.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
### Tipos de Datos
|
|
57
|
+
|
|
58
|
+
**array** : Sirve para declarar listas de objetos, requiere el campo **array* que contiene un formato completo.
|
|
59
|
+
|
|
60
|
+
**bits** : Sirve para declarar una lista de valores booleanos como un arreglo de bits en la cantidad necesaria de bytes. Es opcional el campo **length** si se quiere fijar una cantidad de elementos y usar un byte menos en su codificación.
|
|
61
|
+
|
|
62
|
+
**bool** : Sirve para declarar un único valor booleano en un byte. No requiere campos adicionales, ocupa 1 byte.
|
|
63
|
+
|
|
64
|
+
**char** : Sirve para declarar un único valor booleano en un byte. No requiere campos adicionales, ocupa 1 byte.
|
|
65
|
+
|
|
66
|
+
**date** : Sirve para declarar un valor datetime.date. No requiere campos adicionales, ocupa 3 bytes.
|
|
67
|
+
|
|
68
|
+
**datetime** : Sirve para declarar un valor datetime.datetime con presicion de segundos. No requiere campos adicionales, ocupa 6 bytes.
|
|
69
|
+
|
|
70
|
+
**flags** : Sirve para declarar una lista de keys cuyos valores sean booleanos y representarlos en un arreglo de bits. No requiere campos adicionales.
|
|
71
|
+
|
|
72
|
+
**float** : Sirve para declarar un valor numérico con una precisión fija de decimales. Requiere el campo **bytes** y **decimales**, tamaño variable.
|
|
73
|
+
|
|
74
|
+
**signed** : Sirve para declarar un valor entero positivo. Requiere el campo **bytes**, tamaño variable.
|
|
75
|
+
|
|
76
|
+
**string** : Sirve para declarar un texto. Es opcional el campo **bytes**, tamaño variable.
|
|
77
|
+
|
|
78
|
+
**time** : Sirve para declarar un valor datetime.time con presicion de minutos. No requiere campos adicionales, ocupa 2 bytes.
|
|
79
|
+
|
|
80
|
+
**timestamp** : Sirve para declarar un valor datetime.datetime con presicion de microsegundos. No requiere campos adicionales, ocupa 8 bytes.
|
|
81
|
+
|
|
82
|
+
**unsigned** : Sirve para declarar un valor entero. Requiere el campo **bytes**, tamaño variable.
|
|
@@ -306,9 +306,11 @@ class FieldSigned(FieldBase):
|
|
|
306
306
|
class FieldString(FieldBase):
|
|
307
307
|
|
|
308
308
|
def to_binary(self, val):
|
|
309
|
-
if self.bytes
|
|
310
|
-
utf = str(val).encode('utf')[:
|
|
311
|
-
return
|
|
309
|
+
if self.bytes:
|
|
310
|
+
utf = str(val).encode('utf')[:self.bytes]
|
|
311
|
+
return utf
|
|
312
|
+
utf = str(val).encode('utf')[:255]
|
|
313
|
+
return len(utf).to_bytes(1, 'big') + utf
|
|
312
314
|
|
|
313
315
|
def from_binary(self, binary):
|
|
314
316
|
if self.bytes == 0:
|
|
@@ -217,12 +217,23 @@ class BasicTest(unittest.TestCase):
|
|
|
217
217
|
|
|
218
218
|
class AdvancedTest(unittest.TestCase):
|
|
219
219
|
|
|
220
|
-
def
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
binary = self.parser.encode(DATA, 'report')
|
|
225
|
-
recv = self.parser.decode(binary, 'report')
|
|
220
|
+
def test_file(self):
|
|
221
|
+
protocol = Protocol(file='demo.json')
|
|
222
|
+
binary = protocol.encode(DATA, 'report')
|
|
223
|
+
recv = protocol.decode(binary, 'report')
|
|
226
224
|
self.assertEqual(DATA, recv)
|
|
227
225
|
|
|
226
|
+
def test_json(self):
|
|
227
|
+
protocol = Protocol(js={'medida': [
|
|
228
|
+
{'key': 'id', 'bytes': 1, 'type': 'unsigned'},
|
|
229
|
+
{'key': 'nombre', 'type': 'string'},
|
|
230
|
+
{'key': 'valor', 'bytes': 2, 'type': 'signed'}
|
|
231
|
+
]})
|
|
232
|
+
data = {'id': 2, 'nombre': 'Voltaje', 'valor': -20}
|
|
233
|
+
binary = protocol.encode(data, 'medida')
|
|
234
|
+
print('binary', binary)
|
|
235
|
+
recv = protocol.decode(binary, 'medida')
|
|
236
|
+
print('recv', recv)
|
|
237
|
+
self.assertEqual(data, recv)
|
|
238
|
+
|
|
228
239
|
|
protobin-0.0.2/PKG-INFO
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: protobin
|
|
3
|
-
Version: 0.0.2
|
|
4
|
-
Summary: Python library for encode and decode data in protobin format
|
|
5
|
-
Project-URL: Homepage, https://github.com/drmelectronic/protobin-python
|
|
6
|
-
Project-URL: Bug Tracker, https://github.com/drmelectronic/protobin-python/issues
|
|
7
|
-
Author-email: Daniel Robles <drm.electronic@gmail.com>
|
|
8
|
-
License: MIT License
|
|
9
|
-
|
|
10
|
-
Copyright (c) [Año] [Tu Nombre]
|
|
11
|
-
|
|
12
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
-
in the Software without restriction, including without limitation the rights
|
|
15
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
-
furnished to do so, subject to the following conditions:
|
|
18
|
-
|
|
19
|
-
The above copyright notice and this permission notice shall be included in all
|
|
20
|
-
copies or substantial portions of the Software.
|
|
21
|
-
|
|
22
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
-
SOFTWARE. 1
|
|
29
|
-
1. en.wikipedia.org
|
|
30
|
-
en.wikipedia.org
|
|
31
|
-
License-File: LICENSE.txt
|
|
32
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
-
Classifier: Operating System :: OS Independent
|
|
34
|
-
Classifier: Programming Language :: Python :: 3
|
|
35
|
-
Requires-Python: >=3.9
|
|
36
|
-
Description-Content-Type: text/markdown
|
|
37
|
-
|
|
38
|
-
# protobin
|
|
39
|
-
|
|
40
|
-
**protobin** es una biblioteca Python diseñada para facilitar la interacción con el formato de transferencia de datos Protobin en modo binario. Esta biblioteca proporciona una interfaz sencilla y eficiente para:
|
|
41
|
-
|
|
42
|
-
* **Serializar** objetos Python en datos Protobin.
|
|
43
|
-
* **Deserializar** datos Protobin en objetos Python.
|
|
44
|
-
* **Validar** la integridad de los datos Protobin.
|
|
45
|
-
|
|
46
|
-
## Instalación
|
|
47
|
-
|
|
48
|
-
Para instalar `protobin-python`, puedes utilizar pip:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
pip install protobin
|
protobin-0.0.2/README.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# protobin
|
|
2
|
-
|
|
3
|
-
**protobin** es una biblioteca Python diseñada para facilitar la interacción con el formato de transferencia de datos Protobin en modo binario. Esta biblioteca proporciona una interfaz sencilla y eficiente para:
|
|
4
|
-
|
|
5
|
-
* **Serializar** objetos Python en datos Protobin.
|
|
6
|
-
* **Deserializar** datos Protobin en objetos Python.
|
|
7
|
-
* **Validar** la integridad de los datos Protobin.
|
|
8
|
-
|
|
9
|
-
## Instalación
|
|
10
|
-
|
|
11
|
-
Para instalar `protobin-python`, puedes utilizar pip:
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
pip install protobin
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|