From 65c1f366ef0252d9ce57cb37aae30a085b43bbe9 Mon Sep 17 00:00:00 2001 From: boukeversteegh Date: Wed, 10 Jun 2020 23:47:07 +0200 Subject: [PATCH] Update readme with new output structure and fix example inconsistencies --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8e9f4cd..6c8fe24 100644 --- a/README.md +++ b/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!"}