forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrozen_mutation.cc
88 lines (74 loc) · 2.42 KB
/
frozen_mutation.cc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
/*
* 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/>.
*/
#include "db/serializer.hh"
#include "frozen_mutation.hh"
#include "partition_builder.hh"
#include "mutation_partition_serializer.hh"
#include "utils/UUID.hh"
#include "utils/data_input.hh"
//
// Representation layout:
//
// <mutation> ::= <column-family-id> <partition-key> <partition>
//
using namespace db;
utils::UUID
frozen_mutation::column_family_id() const {
data_input in(_bytes);
return uuid_serializer::read(in);
}
partition_key_view
frozen_mutation::key(const schema& s) const {
data_input in(_bytes);
uuid_serializer::skip(in);
return partition_key_view_serializer::read(in);
}
frozen_mutation::frozen_mutation(bytes&& b)
: _bytes(std::move(b))
{ }
frozen_mutation::frozen_mutation(const mutation& m) {
auto&& id = m.schema()->id();
partition_key_view key_view = m.key();
uuid_serializer id_ser(id);
partition_key_view_serializer key_ser(key_view);
mutation_partition_serializer part_ser(*m.schema(), m.partition());
bytes buf(bytes::initialized_later(), id_ser.size() + key_ser.size() + part_ser.size_without_framing());
data_output out(buf);
id_ser.write(out);
key_ser.write(out);
part_ser.write_without_framing(out);
_bytes = std::move(buf);
}
mutation
frozen_mutation::unfreeze(schema_ptr schema) const {
mutation m(key(*schema), schema);
partition_builder b(*schema, m.partition());
partition().accept(*schema, b);
return m;
}
frozen_mutation freeze(const mutation& m) {
return { m };
}
mutation_partition_view frozen_mutation::partition() const {
data_input in(_bytes);
uuid_serializer::skip(in);
partition_key_view_serializer::skip(in);
return mutation_partition_view::from_bytes(in.read_view(in.avail()));
}