Add Serialisation doc.

pull/15/head
Peter Hinch 2020-02-10 18:17:37 +00:00
rodzic c42d12b7d9
commit 7a7ab42dd7
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -108,7 +108,23 @@ Decoded data (partial): test
more
```
Consequently encoded strings may be separated with `'\n'` before saving and
reading may be done using `readline` methods.
reading may be done using `readline` methods as in this code fragment where
`u` is a UART instance:
```python
s = ujson.dumps(data)
# pickle produces a bytes object whereas ujson produces a string
# In the case of ujson it is probably wise to convert to bytes
u.write(s.encode())
# Pickle:
# u.write(s)
u.write(b'\n')
# receiver
s = u.readline()
v = ujson.loads(s) # ujson can cope with bytes object
# ujson and pickle can cope with trailing newline.
```
# 3. ustruct