forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_info.hh
65 lines (57 loc) · 1.95 KB
/
schema_info.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (C) 2018 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstddef>
namespace data {
/// Type information
///
/// `type_info` keeps the type information relevant for the serialisation code.
/// In particular we need to distinguish between fixed-size and variable-sized
/// types. Collections and counters are considered to be variable-sized types.
///
/// \note Even if the type is fixed-size (e.g. `int32_type`) the value can be
/// empty and its length will be 0. This is a special (and rare) case handled
/// by the cell implementation and ignored by `type_info`.
class type_info {
size_t _fixed_size;
private:
explicit type_info(size_t size) noexcept : _fixed_size(size) { }
public:
static type_info make_fixed_size(size_t size) noexcept {
return type_info { size_t(size) };
}
static type_info make_variable_size() noexcept {
return type_info { 0 };
}
static type_info make_collection() noexcept {
return type_info { 0 };
}
/// Check whether the type is fixed-size.
bool is_fixed_size() const noexcept {
return _fixed_size > 0;
}
/// Get the size of the value of a fixed-size type.
///
/// Valid only if `is_fixed_size()` returns `true`.
size_t value_size() const noexcept {
return _fixed_size;
}
};
}