Skip to content

Commit 2c369e0

Browse files
update readme
1 parent c4d7b52 commit 2c369e0

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

README.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ Compared to Google’s implementation, hpp-proto adopts a minimalistic design th
1515
* Each generated C++ aggregate is associated with static C++ reflection data for efficient Protocol Buffers encoding and decoding.
1616
* All generated message types are equality-comparable, making them useful in unit testing.
1717
* Completely exception-free.
18-
* Supports non-owning mode code generation, mapping string and repeated fields to `std::string_view` and `hpp::proto::equality_comparable_span` which derives from `std::span` and adds the equality comparator.
18+
* Supports non-owning mode code generation, mapping string and repeated fields to `std::string_view` and `hpp::proto::equality_comparable_span` which derives from `std::span` and adds the equality comparator.
19+
Non-owning mode can be enabled globally via [protoc plugin options](docs/Code_Generation_Guide.md##plugin-options)
20+
or selectively using [protobuf extensions](docs/Code_Generation_Guide.md#non-owning-mode-only-for-specific-files-messages-or-fields).
1921
* Enables compile-time serialization.
2022

2123
## Limitations
2224
* Lacks runtime reflection support.
23-
* Lacks support for extra json print options like `always_print_fields_with_no_presence`, `always_print_enums_as_ints`,
25+
* Lacks support for extra json print options in the google C++ protobuf implementation like `always_print_fields_with_no_presence`, `always_print_enums_as_ints`,
2426
`preserve_proto_field_names` or`unquote_int64_if_possible`.
2527
* Unknown fields are always discarded during deserialization.
2628

@@ -340,7 +342,6 @@ assert(out_msg.name == "john");
340342
// Deserialize using the expected return API
341343
expected<Person, std::errc> read_result = read_proto<Person>(in_msg);
342344
assert(read_result.value().name == "john");
343-
344345
```
345346
</p>
346347
</details>
@@ -362,6 +363,38 @@ For most use cases, [std::pmr::monotonic_buffer_resource](https://en.cppreferenc
362363
363364
The option object allows you to specify memory resources for `read_proto()`:
364365
- `alloc_from`: All memory used by the deserialized value is allocated from the provided memory resource.
366+
367+
```cpp
368+
#include <addressbook.pb.hpp> // Include "*.pb.hpp" for Protobuf APIs
369+
370+
// ....
371+
tutorial::Person in_msg, out_msg;
372+
msg1.name = "john";
373+
374+
std::string out_buffer;
375+
using namespace hpp::proto;
376+
// Serialize using the status return API
377+
if (!write_proto(in_msg, out_buffer).ok()) {
378+
// Handle error
379+
}
380+
assert(out_buffer == "\x0a\x04john");
381+
382+
// Serialize using the expected return API
383+
expected<std::string, std::errc> write_result = write_proto<std::string>(in_msg);
384+
assert(write_result.value() == "\x0a\x04john");
385+
386+
std::pmr::monotonic_buffer_resource pool;
387+
std::string_view in_buffer = "\x0a\x04john";
388+
// Deserialize using the status return API
389+
if (!read_proto(out_msg, in_buffer, alloc_from{pool}).ok()) {
390+
// Handle error
391+
}
392+
assert(out_msg.name == "john");
393+
394+
// Deserialize using the expected return API
395+
expected<Person, std::errc> read_result = read_proto<Person>(in_msg, alloc_from{pool});
396+
assert(read_result.value().name == "john");
397+
```
365398
</p>
366399
</details>
367400

0 commit comments

Comments
 (0)