1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2015 Couchbase, Inc
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 #ifndef SRC_EXT_META_PARSER_H_
19 #define SRC_EXT_META_PARSER_H_ 1
20 
21 #include "config.h"
22 
23 #include <memcached/types.h>
24 
25 #include <utility>
26 
27 /**
28  * Version for extras-detail in setWithMeta/delWithMeta and
29  * DCP mutation/expiration
30  */
31 enum cmd_meta_extras_version {
32     /* Extras format: | type:1B | len:2B | field1 | type | len | field2 | ...
33      */
34     META_EXT_VERSION_ONE = 0x01
35 };
36 
37 /**
38  * Definition of extras-types for setWithMeta, delWithMeta
39  * commands and DCP mutation/expiration messages
40  */
41 enum cmd_meta_extras_type {
42     /* adjusted time */
43     CMD_META_ADJUSTED_TIME     = 0x01,
44     /* conflict resolution mode is no longer sent, but could be received on upgrade.*/
45     CMD_META_CONFLICT_RES_MODE = 0x02
46 };
47 
48 /**
49  * This class will be used to parse the extended meta data section
50  * in setWithMeta/delWithMeta commands and DCP mutation/deletion
51  * messages.
52  */
53 class ExtendedMetaData {
54 public:
ExtendedMetaData()55     ExtendedMetaData()
56           : data(nullptr),
57             ret(ENGINE_SUCCESS),
58             len(0) {}
59 
60     ExtendedMetaData(const void *meta, uint16_t nmeta);
61 
getStatus()62     ENGINE_ERROR_CODE getStatus() {
63         return ret;
64     }
65 
getExtMeta()66     std::pair<const char*, uint16_t> getExtMeta() {
67         return std::make_pair(data, len);
68     }
69 
70 private:
71     /*
72     void encodeMeta(); is currently removed as there's no extmeta to encode.
73     Resurrect from history as required.
74     */
75     void decodeMeta();
76 
77     const char* data;
78     ENGINE_ERROR_CODE ret;
79     uint16_t len;
80 };
81 
82 #endif  // SRC_EXT_META_PARSER_H_
83