MUST have extras. MUST have key. MAY have value. Extra data for set/add/replace: Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| Flags
| 1092 | // +---------------+---------------+---------------+---------------+ |
| 1093 | // Total 8 bytes |
| 1094 | bool CouchbaseOperations::CouchbaseRequest::store( |
| 1095 | uint8_t command, const butil::StringPiece& key, |
| 1096 | const butil::StringPiece& value, uint32_t flags, uint32_t exptime, |
| 1097 | uint64_t cas_value, uint8_t coll_id) { |
| 1098 | // add collection id |
| 1099 | // uint16_t collection_id = 0x00; |
| 1100 | uint8_t collection_id = coll_id; |
| 1101 | uint16_t vBucket_id = hashCrc32(key.data(), key.size()); |
| 1102 | StoreHeaderWithExtras header_with_extras = { |
| 1103 | {policy::CB_MAGIC_REQUEST, command, |
| 1104 | butil::HostToNet16(key.size() + |
| 1105 | 1), // collection id is not included in part of key, |
| 1106 | // so not including it in key length. |
| 1107 | STORE_EXTRAS, policy::CB_JSON, butil::HostToNet16(vBucket_id), |
| 1108 | butil::HostToNet32(STORE_EXTRAS + sizeof(collection_id) + key.size() + |
| 1109 | value.size()), // total body length |
| 1110 | 0, butil::HostToNet64(cas_value)}, |
| 1111 | butil::HostToNet32(flags), |
| 1112 | butil::HostToNet32(exptime)}; |
| 1113 | if (_buf.append(&header_with_extras, sizeof(header_with_extras))) { |
| 1114 | return false; |
| 1115 | } |
| 1116 | if (_buf.append(&collection_id, sizeof(collection_id))) { |
| 1117 | return false; |
| 1118 | } |
| 1119 | if (_buf.append(key.data(), key.size())) { |
| 1120 | return false; |
| 1121 | } |
| 1122 | if (_buf.append(value.data(), value.size())) { |
| 1123 | return false; |
| 1124 | } |
| 1125 | ++_pipelined_count; |
| 1126 | return true; |
| 1127 | } |
| 1128 | |
| 1129 | // MUST have CAS |
| 1130 | // MUST NOT have extras |