Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
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
23{
24
40constexpr std::uint32_t common_format_mask = 0x0F000000;
41
42enum class common_flags : std::uint32_t {
43 reserved = 0x00,
44 client_specific = 0x01, // called PRIVATE in RFC and other SDKs
45 json = 0x02,
46 binary = 0x03,
47 string = 0x04
48};
49
56constexpr auto
57create_common_flags(common_flags flags) -> std::uint32_t
58{
59 return static_cast<std::uint32_t>(flags) << 24U;
60}
61
70constexpr auto
71extract_common_flags(std::uint32_t flags) -> common_flags
72{
73 switch (auto value = static_cast<common_flags>(flags >> 24U)) {
78 return value;
79 default:
80 break;
81 }
83}
84
94constexpr auto
95has_common_flags(std::uint32_t flags) -> bool
96{
98}
99
108constexpr auto
109has_common_flags(std::uint32_t flags, std::uint32_t expected_common_flag) -> bool
110{
111 return has_common_flags(flags) && (flags & common_format_mask) == expected_common_flag;
112}
113
122constexpr auto
123has_common_flags(std::uint32_t flags, common_flags expected_common_flag) -> bool
124{
125 return has_common_flags(flags) &&
126 (flags & common_format_mask) == create_common_flags(expected_common_flag);
127}
128
138constexpr auto
139has_compression_flags(std::uint32_t flags) -> bool
140{
141 return (flags >> 29U) > 0;
142}
143
148} // namespace couchbase::codec::codec_flags
Definition codec_flags.hxx:23
constexpr std::uint32_t binary_common_flags
Definition codec_flags.hxx:146
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:95
constexpr std::uint32_t string_common_flags
Definition codec_flags.hxx:147
common_flags
Definition codec_flags.hxx:42
constexpr std::uint32_t private_common_flags
Definition codec_flags.hxx:144
constexpr auto extract_common_flags(std::uint32_t flags) -> common_flags
Returns only the common flags from the full flags.
Definition codec_flags.hxx:71
constexpr std::uint32_t common_format_mask
32bit flag is composed of:
Definition codec_flags.hxx:40
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:139
constexpr std::uint32_t json_common_flags
Definition codec_flags.hxx:145
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:57
std::vector< std::byte > binary
Definition encoded_value.hxx:25