/Users/deen/code/yugabyte-db/src/yb/common/wire_protocol-test-util.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/common/wire_protocol-test-util.h" |
15 | | |
16 | | #include "yb/docdb/doc_key.h" |
17 | | |
18 | | namespace yb { |
19 | | |
20 | | void AddKVToPB(int32_t key_val, |
21 | | int32_t int_val, |
22 | | const string& string_val, |
23 | 1.04M | docdb::KeyValueWriteBatchPB* write_batch) { |
24 | 1.04M | const ColumnId int_val_col_id(kFirstColumnId + 1); |
25 | 1.04M | const ColumnId string_val_col_id(kFirstColumnId + 2); |
26 | | |
27 | 1.04M | auto add_kv_pair = |
28 | 2.08M | [&](const SubDocKey &subdoc_key, const PrimitiveValue &primitive_value) { |
29 | 2.08M | KeyValuePairPB *const kv = write_batch->add_write_pairs(); |
30 | 2.08M | kv->set_key(subdoc_key.Encode().ToStringBuffer()); |
31 | 2.08M | kv->set_value(primitive_value.ToValue()); |
32 | 2.08M | }; |
33 | | |
34 | 1.04M | std::string hash_key; |
35 | 1.04M | YBPartition::AppendIntToKey<int32_t, uint32_t>(key_val, &hash_key); |
36 | 1.04M | auto hash = YBPartition::HashColumnCompoundValue(hash_key); |
37 | 1.04M | const DocKey doc_key(hash, {PrimitiveValue::Int32(key_val)}, {}); |
38 | 1.04M | add_kv_pair(SubDocKey(doc_key, PrimitiveValue(int_val_col_id)), |
39 | 1.04M | PrimitiveValue::Int32(int_val)); |
40 | 1.04M | add_kv_pair(SubDocKey(doc_key, PrimitiveValue(string_val_col_id)), |
41 | 1.04M | PrimitiveValue(string_val)); |
42 | 1.04M | } |
43 | | |
44 | | } // namespace yb |