diff --git a/README.md b/README.md index d817fa4..06d54e7 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,30 @@ def custom_convert(value): convert(value, custom_serializer=custom_convert) ``` + +## Proto File Generation + +[Protocol Buffers](https://developers.google.com/protocol-buffers/docs/proto) are a powerful tool +to describe structured data. In addition to the undocument json serialization it is useful to add +a proto serialization which can be used in many other contexts such as API client generation or +docs generation. + +You can try it out via + +```python +python3 example.py > sample.proto +``` + +> A prerequisite is to install []() and [`protoc`](). This is an example install command for mac: +> ```shell +> brew install protobuf +> go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest +> ``` + +And then generate the docs via +```shell +protoc --doc_out=./docs --doc_opt=html,docs.html sample.proto +protoc --doc_out=./docs --doc_opt=markdown,docs.md sample.proto +``` + +Check out the docs in the [`/docs`](/docs) directory. diff --git a/docs/docs.html b/docs/docs.html new file mode 100644 index 0000000..05b079d --- /dev/null +++ b/docs/docs.html @@ -0,0 +1,468 @@ + + + +
+Field | Type | Label | Description |
name | +string | +required | +the name of the person |
+
age | +int32 | +optional | +the age of the person |
+
hobby | +string | +optional | +the hobby of the person |
+
Field | Type | Label | Description |
person | +person | +required | +a person object |
+
.proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
double | ++ | double | +double | +float | +float64 | +double | +float | +Float | +
float | ++ | float | +float | +float | +float32 | +float | +float | +Float | +
int32 | +Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | +int32 | +int | +int | +int32 | +int | +integer | +Bignum or Fixnum (as required) | +
int64 | +Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | +int64 | +long | +int/long | +int64 | +long | +integer/string | +Bignum | +
uint32 | +Uses variable-length encoding. | +uint32 | +int | +int/long | +uint32 | +uint | +integer | +Bignum or Fixnum (as required) | +
uint64 | +Uses variable-length encoding. | +uint64 | +long | +int/long | +uint64 | +ulong | +integer/string | +Bignum or Fixnum (as required) | +
sint32 | +Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | +int32 | +int | +int | +int32 | +int | +integer | +Bignum or Fixnum (as required) | +
sint64 | +Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | +int64 | +long | +int/long | +int64 | +long | +integer/string | +Bignum | +
fixed32 | +Always four bytes. More efficient than uint32 if values are often greater than 2^28. | +uint32 | +int | +int | +uint32 | +uint | +integer | +Bignum or Fixnum (as required) | +
fixed64 | +Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | +uint64 | +long | +int/long | +uint64 | +ulong | +integer/string | +Bignum | +
sfixed32 | +Always four bytes. | +int32 | +int | +int | +int32 | +int | +integer | +Bignum or Fixnum (as required) | +
sfixed64 | +Always eight bytes. | +int64 | +long | +int/long | +int64 | +long | +integer/string | +Bignum | +
bool | ++ | bool | +boolean | +boolean | +bool | +bool | +boolean | +TrueClass/FalseClass | +
string | +A string must always contain UTF-8 encoded or 7-bit ASCII text. | +string | +String | +str/unicode | +string | +string | +string | +String (UTF-8) | +
bytes | +May contain any arbitrary sequence of bytes. | +string | +ByteString | +str | +[]byte | +ByteString | +string | +String (ASCII-8BIT) | +