Update minipb examples

- Clarify why packed repeated fields might be useful and under what circumstances are these not recommended.
- Remove the redundant ']'s from nested schemas. They do nothing and could potentially make future updates to the schema format difficult.
- Update dependencies.
pull/31/head
dogtopus 2023-03-06 00:30:45 -04:00 zatwierdzone przez GitHub
rodzic 6c478601a6
commit ffb7eefc1f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 21 dodań i 7 usunięć

Wyświetl plik

@ -321,7 +321,7 @@ by a single string.
## 5.1 Installation ## 5.1 Installation
The library comprises a single file `minipb.py`. It has a dependency, the The library comprises a single file `minipb.py`. It has a dependency, the
`logging` module `logging.py` which may be found in `logging` module `logging.py` and `bisect` module `bisect.py` which may be found in
[micropython-lib](https://github.com/micropython/micropython-lib/tree/master/logging). [micropython-lib](https://github.com/micropython/micropython-lib/tree/master/logging).
On RAM constrained platforms `minipb.py` may be cross-compiled or frozen as On RAM constrained platforms `minipb.py` may be cross-compiled or frozen as
bytecode for even lower RAM consumption. bytecode for even lower RAM consumption.
@ -342,7 +342,7 @@ a subset may be used which maps onto Python data types:
an ingenious algorithm. an ingenious algorithm.
6. 'd' A double precision 64-bit float. The default on Pyboard D SF6. Also on 6. 'd' A double precision 64-bit float. The default on Pyboard D SF6. Also on
other platforms with special firmware builds. other platforms with special firmware builds.
7. 'X' An empty field. 7. 'x' An empty field.
## 5.2.1 Required and Optional fields ## 5.2.1 Required and Optional fields
@ -447,9 +447,23 @@ print(rx)
``` ```
### 5.5.1 Packed repeating fields ### 5.5.1 Packed repeating fields
This feature reduces some space overhead of encoded message caused by repeatedly
emitting field headers as seen in regular repeated fields.
```python
>>> import minipb
>>> normal=minipb.Wire('+z')
>>> len(normal.encode(range(10000)))
31744
>>> packed=minipb.Wire('#z')
>>> len(packed.encode(range(10000)))
21748
>>>
```
The author of `minipb` [does not recommend](https://github.com/dogtopus/minipb/issues/6) The author of `minipb` [does not recommend](https://github.com/dogtopus/minipb/issues/6)
their use. Their purpose appears to be in the context of fixed-length fields their use for strings, bytes and nested messages due to compatibility concerns with the
which are outside the scope of pure Python programming. official Google Protobuf standards, which disallows such use.
## 5.6 Message fields (nested dicts) ## 5.6 Message fields (nested dicts)
@ -468,7 +482,7 @@ nested_schema = (('str2', 'U'),
# Outer schema # Outer schema
schema = (('number', 'z'), schema = (('number', 'z'),
('string', 'U'), ('string', 'U'),
('nested', '+[', nested_schema, ']'), ('nested', '+[', nested_schema),
('num', 'z'),) ('num', 'z'),)
w = minipb.Wire(schema) w = minipb.Wire(schema)
@ -501,11 +515,11 @@ import minipb
inner_schema = (('str2', 'U'), inner_schema = (('str2', 'U'),
('num2', 'z'),) ('num2', 'z'),)
nested_schema = (('inner', '+[', inner_schema, ']'),) nested_schema = (('inner', '+[', inner_schema),)
schema = (('number', 'z'), schema = (('number', 'z'),
('string', 'U'), ('string', 'U'),
('nested', '[', nested_schema, ']'), ('nested', '[', nested_schema),
('num', 'z'),) ('num', 'z'),)
w = minipb.Wire(schema) w = minipb.Wire(schema)