C++ RAII wrappers for grpc_byte_buffer/grpc_slice & friends

97 views
Skip to first unread message

Christopher Warrington - MSFT

unread,
Oct 27, 2017, 4:38:27 PM10/27/17
to grpc.io
Are there any C++ RAII wrappers for grpc_byte_buffer/grpc_slice/grpc_byte_buffer_reader & friends? I couldn't find any in a cursory look.
I only really interact with these types in my specialization of grpc::SerializationTraits. The rest of the time I'm well insulated from them.

-- 
Christopher Warrington
Microsoft

Vijay Pai

unread,
Oct 28, 2017, 1:00:45 PM10/28/17
to grpc.io
grpc::Slice drops a reference to the underlying grpc_slice at destruction time; if you use that in combination with the StealRef second argument, I think that you would have what you essentially want. (FWIW, the constructor for grpc::Slice that takes a grpc_slice is not really recommended since grpc_slice itself is core API which changes a lot more rapidly than C++ API).

grpc::ByteBuffer uses grpc_byte_buffer in its implementation but does not have a constructor that takes in a grpc_byte_buffer.  There is an issue filed to improve the characteristics of grpc::ByteBuffer but no consideration of adding a constructor that pulls from a grpc_byte_buffer (again, since C++ API should avoid requiring the use of core API features).

Christopher Warrington - MSFT

unread,
Oct 30, 2017, 7:44:29 PM10/30/17
to grpc.io
On Saturday, October 28, 2017 at 10:00:45 AM UTC-7, Vijay Pai wrote:

> grpc::Slice drops a reference to the underlying grpc_slice at destruction
> time; if you use that in combination with the StealRef second argument, I
> think that you would have what you essentially want. (FWIW, the
> constructor for grpc::Slice that takes a grpc_slice is not really
> recommended since grpc_slice itself is core API which changes a lot more
> rapidly than C++ API).

Thanks for the pointer. I see it, and it helps cover one place where I was
missing exception safety.

> grpc::ByteBuffer uses grpc_byte_buffer in its implementation but does not
> have a constructor that takes in a grpc_byte_buffer. There is an issue
> filed to improve the characteristics of grpc::ByteBuffer but no
> consideration of adding a constructor that pulls from a grpc_byte_buffer
> (again, since C++ API should avoid requiring the use of core API
> features).

The version I'm using is behind a bit, so I don't yet have commit
87973ea398 [1] that added support for using ByteBuffer to implement
SerializationTraits. Once I can pick that up, I can switch to ByteBuffer,
so my use case doesn't need a grpc_byte_buffer ctor either.

The improvements proposed in issue #12296 [2] will help with my
implementation of SerializationTraits, so I'm looking forward to
them.


-- 
Christopher Warrington
Microsoft
Reply all
Reply to author
Forward
0 new messages