[C++] Improve flatbuffers + gRPC integration (#4310)
authorLawrence Chan <llchan@users.noreply.github.com>
Wed, 7 Jun 2017 20:56:49 +0000 (15:56 -0500)
committerWouter van Oortmerssen <aardappel@gmail.com>
Wed, 7 Jun 2017 20:56:49 +0000 (13:56 -0700)
commitda67c0a71f98b8bab59aacd424b8648a9e293476
tree7bd7ab93e57bb179f85f9f7858d033490c69eebe
parentdadd1a926ee75cad9d9ef792edcbc902b1f1744a
[C++] Improve flatbuffers + gRPC integration (#4310)

* Rework flatbuffers + gRPC integration

- Introduce `flatbuffers::grpc::Message<T>`, a `grpc_slice`-backed
message buffer that handles refcounting and allows flatbuffers to
transfer ownership to gRPC efficiently. This replaces
`flatbuffers::BufferRef<T>`, which required a copy call and was also
unsafe w.r.t. buffer lifetime.
- Introduce `flatbuffers::grpc::MessageBuilder`, a gRPC-specific builder
that forces a `grpc_slice`-backed allocator and also adds some helpful
`Message<T>`-related methods.
- Update serializers accordingly (now zero-copy between flatbuffers and
gRPC).

* gRPC: verify messages by default, but allow user to override

* gRPC: fix some formatting issues

* Disable verification by default, but add helper method

* Make FlatBufferBuilder fields protected + remove vec accessor

* Use bool add_ref parameter to toggle refcount incr

* Remove unnecessary inline specifiers

* Fix formatting

* Use auto

* Remove empty lines

* Use grpc_slice helper macros

* Simplify reset code

* Disable Message copy ctor and assignment by default

* Remove unused member

* Enable gRPC verification by default

* Use auto

* Bake in message verification (remove template specialization)

* Add RoundUp func

* Consolidate gRPC message copy flag

* Make vector_downward allocations fully lazy

* Test message verification failure code/message

* Add grpctest verification test comments

* Simplify reallocate implementation

* Make initial_size a size_t

* Use ternary op for growth_policy

* Use truthiness rather than dont explicit nullptr check

* Indent preprocessor directives

* Remove grpc message copy/assignment

* Fix a few bugs

* Add gRPC example

* Add basic gRPC docs

* Use doxygen EXAMPLE_PATH + @include

* Reference example fbs in grpc docs

* Move gRPC examples into grpc/samples

* Fix pointer/reference formatting

* Use std::function rather than templated callback func

* Create fresh message builder for each request

* Use Clear() in Reset() impl

* Use FLATBUFFERS_CONSTEXPR
15 files changed:
CMakeLists.txt
docs/source/doxyfile
docs/source/doxygen_layout.xml
docs/source/gRPC/CppUsage.md [new file with mode: 0644]
grpc/samples/greeter/Makefile [new file with mode: 0644]
grpc/samples/greeter/client.cpp [new file with mode: 0644]
grpc/samples/greeter/greeter.fbs [new file with mode: 0644]
grpc/samples/greeter/server.cpp [new file with mode: 0644]
grpc/tests/grpctest.cpp
include/flatbuffers/base.h
include/flatbuffers/flatbuffers.h
include/flatbuffers/grpc.h
src/idl_gen_grpc.cpp
tests/monster_test.grpc.fb.cc
tests/monster_test.grpc.fb.h