Update readme with new output structure and fix example inconsistencies
This commit is contained in:
parent
34c34bd15a
commit
65c1f366ef
25
README.md
25
README.md
@ -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!"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user