MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / DecodeRpcRow

Function DecodeRpcRow

src/codec/sql_rpc_row_codec.cc:22–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace codec {
21
22bool DecodeRpcRow(const butil::IOBuf& buf, size_t offset, size_t size, size_t slice_num, hybridse::codec::Row* row) {
23 if (row == nullptr) {
24 return false;
25 }
26 if (slice_num == 0 || size == 0) {
27 *row = hybridse::codec::Row();
28 return true;
29 }
30 size_t cur_offset = offset;
31 if (cur_offset >= buf.size()) {
32 LOG(WARNING) << "Offset " << cur_offset << " out of bound, buf size=" << buf.size();
33 return false;
34 }
35 for (size_t i = 0; i < slice_num; ++i) {
36 uint32_t slice_size;
37 buf.copy_to(&slice_size, sizeof(uint32_t), cur_offset + 2);
38 size_t next_offset;
39 if (slice_size == 0) {
40 next_offset = cur_offset + 2 + sizeof(uint32_t);
41 } else {
42 next_offset = cur_offset + slice_size;
43 }
44 if (next_offset > buf.size()) {
45 LOG(WARNING) << "Size " << slice_size << " for " << i
46 << "th row slice out of bound, buf size=" << buf.size() << " cur offset=" << cur_offset;
47 return false;
48 }
49 if (slice_size == 0) {
50 if (i == 0) {
51 *row = hybridse::codec::Row();
52 } else {
53 row->Append(hybridse::base::RefCountedSlice());
54 }
55 } else {
56 int8_t* slice_buf = reinterpret_cast<int8_t*>(malloc(slice_size));
57 buf.copy_to(slice_buf, slice_size, cur_offset);
58 if (i == 0) {
59 *row = hybridse::codec::Row(hybridse::base::RefCountedSlice::CreateManaged(slice_buf, slice_size));
60 } else {
61 row->Append(hybridse::base::RefCountedSlice::CreateManaged(slice_buf, slice_size));
62 }
63 }
64 cur_offset = next_offset;
65 }
66 if (offset + size != cur_offset) {
67 LOG(WARNING) << "Illegal total row size " << (cur_offset - offset) << ", expect size=" << size;
68 return false;
69 }
70 return true;
71}
72
73bool EncodeRpcRow(const hybridse::codec::Row& row, butil::IOBuf* buf, size_t* total_size) {
74 if (buf == nullptr) {

Callers 5

RunRequestQueryMethod · 0.85
TEST_FFunction · 0.85
client_manager.ccFile · 0.85
SyncRpcResponseMethod · 0.85

Calls 2

sizeMethod · 0.45
AppendMethod · 0.45

Tested by 1

TEST_FFunction · 0.68