1 /*
2  *     Copyright 2019 Couchbase, Inc.
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16 #pragma once
17 
18 #include <memcached/durability_spec.h>
19 #include <cstdint>
20 #include <vector>
21 
22 /**
23  * Base class for all FrameInfo objects
24  */
25 class FrameInfo {
26 public:
27     virtual ~FrameInfo();
28     /**
29      * Encode this FrameInfo object into the on the wire specification
30      * for this FrameInfo object.
31      */
32     virtual std::vector<uint8_t> encode() const = 0;
33 };
34 
35 class BarrierFrameInfo : public FrameInfo {
36 public:
37     ~BarrierFrameInfo() override;
38     std::vector<uint8_t> encode() const override;
39 };
40 
41 class DurabilityFrameInfo : public FrameInfo {
42 public:
DurabilityFrameInfo(cb::durability::Level level, cb::durability::Timeout timeout = {})43     DurabilityFrameInfo(cb::durability::Level level,
44                         cb::durability::Timeout timeout = {})
45         : level(level), timeout(timeout) {
46     }
47     ~DurabilityFrameInfo() override;
48     std::vector<uint8_t> encode() const override;
49 
50 protected:
51     const cb::durability::Level level;
52     const cb::durability::Timeout timeout;
53 };
54 
55 class DcpStreamIdFrameInfo : public FrameInfo {
56 public:
DcpStreamIdFrameInfo(uint16_t id)57     DcpStreamIdFrameInfo(uint16_t id) : id(id){};
58     ~DcpStreamIdFrameInfo() override;
59     std::vector<uint8_t> encode() const override;
60 
61 protected:
62     const uint16_t id;
63 };
64 
65 class OpenTracingContextFrameInfo : public FrameInfo {
66 public:
OpenTracingContextFrameInfo(std::string ctx)67     OpenTracingContextFrameInfo(std::string ctx) : ctx(std::move(ctx)) {
68     }
69     ~OpenTracingContextFrameInfo() override;
70     std::vector<uint8_t> encode() const override;
71 
72 protected:
73     const std::string ctx;
74 };
75