MCPcopy Create free account
hub / github.com/apache/brpc / PackStreamMessage

Function PackStreamMessage

src/brpc/policy/streaming_rpc_protocol.cpp:42–59  ·  view source on GitHub ↗

Notes on Streaming RPC Protocol: 1 - Header format is [STRM][body_size][meta_size], 12 bytes in total 2 - body_size and meta_size are in network byte order

Source from the content-addressed store, hash-verified

40// 1 - Header format is [STRM][body_size][meta_size], 12 bytes in total
41// 2 - body_size and meta_size are in network byte order
42void PackStreamMessage(butil::IOBuf* out,
43 const StreamFrameMeta &fm,
44 const butil::IOBuf *data) {
45 const uint32_t data_length = data ? data->length() : 0;
46 const uint32_t meta_length = GetProtobufByteSize(fm);
47 char head[12];
48 uint32_t* dummy = (uint32_t*)head; // suppresses strict-alias warning
49 *(uint32_t*)dummy = *(const uint32_t*)"STRM";
50 butil::RawPacker(head + 4)
51 .pack32(data_length + meta_length)
52 .pack32(meta_length);
53 out->append(head, ARRAY_SIZE(head));
54 butil::IOBufAsZeroCopyOutputStream wrapper(out);
55 CHECK(fm.SerializeToZeroCopyStream(&wrapper));
56 if (data != NULL) {
57 out->append(*data);
58 }
59}
60
61ParseResult ParseStreamingMessage(butil::IOBuf* source,
62 Socket* socket, bool /*read_eof*/, const void* /*arg*/) {

Callers 5

SendFeedbackMethod · 0.85
SendStreamRstFunction · 0.85
SendStreamCloseFunction · 0.85
SendStreamDataFunction · 0.85

Calls 4

GetProtobufByteSizeFunction · 0.85
RawPackerClass · 0.85
lengthMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected