Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
Loading...
Searching...
No Matches
codec_flags.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2020-Present 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#pragma once
19
20#include <cinttypes>
21#include <vector>
22
24{
25
41constexpr std::uint32_t common_format_mask = 0x0F000000;
42
43enum class common_flags : std::uint32_t {
44 reserved = 0x00,
45 client_specific = 0x01, // called PRIVATE in RFC and other SDKs
46 json = 0x02,
47 binary = 0x03,
48 string = 0x04
49};
50
57constexpr auto
58create_common_flags(common_flags flags) -> std::uint32_t
59{
60 return static_cast<std::uint32_t>(flags) << 24U;
61}
62
71constexpr auto
72extract_common_flags(std::uint32_t flags) -> common_flags
73{
74 switch (auto value = static_cast<common_flags>(flags >> 24U)) {
79 return value;
80 default:
81 break;
82 }
84}
85
95constexpr auto
96has_common_flags(std::uint32_t flags) -> bool
97{
99}
100
109constexpr auto
110has_common_flags(std::uint32_t flags, std::uint32_t expected_common_flag) -> bool
111{
112 return has_common_flags(flags) && (flags & common_format_mask) == expected_common_flag;
113}
114
123constexpr auto
124has_common_flags(std::uint32_t flags, common_flags expected_common_flag) -> bool
125{
126 return has_common_flags(flags) &&
127 (flags & common_format_mask) == create_common_flags(expected_common_flag);
128}
129
139constexpr auto
140has_compression_flags(std::uint32_t flags) -> bool
141{
142 return (flags >> 29U) > 0;
143}
144
149} // namespace couchbase::codec::codec_flags
Definition codec_flags.hxx:24
constexpr std::uint32_t binary_common_flags
Definition codec_flags.hxx:147
constexpr auto has_common_flags(std::uint32_t flags) -> bool
Checks whether the upper 8 bits are set, indicating common flags presence.
Definition codec_flags.hxx:96
constexpr std::uint32_t string_common_flags
Definition codec_flags.hxx:148
common_flags
Definition codec_flags.hxx:43
constexpr std::uint32_t private_common_flags
Definition codec_flags.hxx:145
constexpr auto extract_common_flags(std::uint32_t flags) -> common_flags
Returns only the common flags from the full flags.
Definition codec_flags.hxx:72
constexpr std::uint32_t common_format_mask
32bit flag is composed of:
Definition codec_flags.hxx:41
constexpr auto has_compression_flags(std::uint32_t flags) -> bool
Checks whether the upper 3 bits are set, indicating compression presence.
Definition codec_flags.hxx:140
constexpr std::uint32_t json_common_flags
Definition codec_flags.hxx:146
constexpr auto create_common_flags(common_flags flags) -> std::uint32_t
Takes a enum representation of common flags and moves them to the common flags MSBs.
Definition codec_flags.hxx:58
std::vector< std::byte > binary
Definition encoded_value.hxx:25