byte_buffer_proto_helper.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #include "absl/memory/memory.h"
22 
23 namespace grpc {
24 namespace testing {
25 
27  std::vector<Slice> slices;
28  (void)buffer->Dump(&slices);
30  buf.reserve(buffer->Length());
31  for (auto s = slices.begin(); s != slices.end(); s++) {
32  buf.append(reinterpret_cast<const char*>(s->begin()), s->size());
33  }
34  return message->ParseFromString(buf);
35 }
36 
37 std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
40  message->SerializeToString(&buf);
41  Slice slice(buf);
42  return absl::make_unique<ByteBuffer>(&slice, 1);
43 }
44 
46  ByteBuffer* buffer) {
48  if (!message->SerializeToString(&buf)) {
49  return false;
50  }
51  buffer->Clear();
52  Slice slice(buf);
53  ByteBuffer tmp(&slice, 1);
54  buffer->Swap(&tmp);
55  return true;
56 }
57 
58 } // namespace testing
59 } // namespace grpc
testing
Definition: aws_request_signer_test.cc:25
grpc
Definition: grpcpp/alarm.h:33
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::protobuf::Message
GRPC_CUSTOM_MESSAGE Message
Definition: include/grpcpp/impl/codegen/config_protobuf.h:78
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
grpc::testing::ParseFromByteBuffer
bool ParseFromByteBuffer(ByteBuffer *buffer, grpc::protobuf::Message *message)
Definition: byte_buffer_proto_helper.cc:26
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
grpc::testing::SerializeToByteBufferInPlace
bool SerializeToByteBufferInPlace(grpc::protobuf::Message *message, ByteBuffer *buffer)
Definition: byte_buffer_proto_helper.cc:45
grpc::testing::SerializeToByteBuffer
std::unique_ptr< ByteBuffer > SerializeToByteBuffer(grpc::protobuf::Message *message)
Definition: byte_buffer_proto_helper.cc:37
grpc::ByteBuffer
A sequence of bytes.
Definition: include/grpcpp/impl/codegen/byte_buffer.h:61
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
slices
SliceBuffer * slices
Definition: retry_filter.cc:631
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
grpc::Slice
Definition: include/grpcpp/impl/codegen/slice.h:36
byte_buffer_proto_helper.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:41