Update readme with new output structure and fix example inconsistencies

This commit is contained in:
boukeversteegh 2020-06-10 23:47:07 +02:00
parent 34c34bd15a
commit 65c1f366ef

View File

@ -68,14 +68,15 @@ message Greeting {
You can run the following:
```sh
$ protoc -I . --python_betterproto_out=. example.proto
$ mkdir lib
$ protoc -I . --python_betterproto_out=lib example.proto
```
This will generate `hello.py` which looks like:
This will generate `lib/hello/__init__.py` which looks like:
```py
```python
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: hello.proto
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
@ -83,7 +84,7 @@ import betterproto
@dataclass
class Hello(betterproto.Message):
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
message: str = betterproto.string_field(1)
@ -91,23 +92,23 @@ class Hello(betterproto.Message):
Now you can use it!
```py
>>> from hello import Hello
>>> test = Hello()
```python
>>> from lib.hello import Greeting
>>> test = Greeting()
>>> test
Hello(message='')
Greeting(message='')
>>> test.message = "Hey!"
>>> test
Hello(message="Hey!")
Greeting(message="Hey!")
>>> serialized = bytes(test)
>>> serialized
b'\n\x04Hey!'
>>> another = Hello().parse(serialized)
>>> another = Greeting().parse(serialized)
>>> another
Hello(message="Hey!")
Greeting(message="Hey!")
>>> another.to_dict()
{"message": "Hey!"}