1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "cls/journal/cls_journal_types.h"
5 #include "include/stringify.h"
6 #include "common/Formatter.h"
11 void ObjectPosition::encode(bufferlist& bl) const {
12 ENCODE_START(1, 1, bl);
13 ::encode(object_number, bl);
14 ::encode(tag_tid, bl);
15 ::encode(entry_tid, bl);
19 void ObjectPosition::decode(bufferlist::iterator& iter) {
20 DECODE_START(1, iter);
21 ::decode(object_number, iter);
22 ::decode(tag_tid, iter);
23 ::decode(entry_tid, iter);
27 void ObjectPosition::dump(Formatter *f) const {
28 f->dump_unsigned("object_number", object_number);
29 f->dump_unsigned("tag_tid", tag_tid);
30 f->dump_unsigned("entry_tid", entry_tid);
33 void ObjectPosition::generate_test_instances(std::list<ObjectPosition *> &o) {
34 o.push_back(new ObjectPosition());
35 o.push_back(new ObjectPosition(1, 2, 3));
38 void ObjectSetPosition::encode(bufferlist& bl) const {
39 ENCODE_START(1, 1, bl);
40 ::encode(object_positions, bl);
44 void ObjectSetPosition::decode(bufferlist::iterator& iter) {
45 DECODE_START(1, iter);
46 ::decode(object_positions, iter);
50 void ObjectSetPosition::dump(Formatter *f) const {
51 f->open_array_section("object_positions");
52 for (auto &pos : object_positions) {
53 f->open_object_section("object_position");
60 void ObjectSetPosition::generate_test_instances(
61 std::list<ObjectSetPosition *> &o) {
62 o.push_back(new ObjectSetPosition());
63 o.push_back(new ObjectSetPosition({{0, 1, 120}, {121, 2, 121}}));
66 void Client::encode(bufferlist& bl) const {
67 ENCODE_START(1, 1, bl);
70 ::encode(commit_position, bl);
71 ::encode(static_cast<uint8_t>(state), bl);
75 void Client::decode(bufferlist::iterator& iter) {
76 DECODE_START(1, iter);
79 ::decode(commit_position, iter);
82 ::decode(state_raw, iter);
83 state = static_cast<ClientState>(state_raw);
87 void Client::dump(Formatter *f) const {
88 f->dump_string("id", id);
90 std::stringstream data_ss;
91 data.hexdump(data_ss);
92 f->dump_string("data", data_ss.str());
94 f->open_object_section("commit_position");
95 commit_position.dump(f);
98 f->dump_string("state", stringify(state));
101 void Client::generate_test_instances(std::list<Client *> &o) {
103 data.append(std::string(128, '1'));
105 o.push_back(new Client());
106 o.push_back(new Client("id", data));
107 o.push_back(new Client("id", data, {{{1, 2, 120}, {2, 3, 121}}}));
110 void Tag::encode(bufferlist& bl) const {
111 ENCODE_START(1, 1, bl);
113 ::encode(tag_class, bl);
118 void Tag::decode(bufferlist::iterator& iter) {
119 DECODE_START(1, iter);
121 ::decode(tag_class, iter);
122 ::decode(data, iter);
126 void Tag::dump(Formatter *f) const {
127 f->dump_unsigned("tid", tid);
128 f->dump_unsigned("tag_class", tag_class);
130 std::stringstream data_ss;
131 data.hexdump(data_ss);
132 f->dump_string("data", data_ss.str());
135 void Tag::generate_test_instances(std::list<Tag *> &o) {
136 o.push_back(new Tag());
139 data.append(std::string(128, '1'));
140 o.push_back(new Tag(123, 234, data));
143 std::ostream &operator<<(std::ostream &os, const ClientState &state) {
145 case CLIENT_STATE_CONNECTED:
148 case CLIENT_STATE_DISCONNECTED:
149 os << "disconnected";
152 os << "unknown (" << static_cast<uint32_t>(state) << ")";
158 std::ostream &operator<<(std::ostream &os,
159 const ObjectPosition &object_position) {
161 << "object_number=" << object_position.object_number << ", "
162 << "tag_tid=" << object_position.tag_tid << ", "
163 << "entry_tid=" << object_position.entry_tid << "]";
167 std::ostream &operator<<(std::ostream &os,
168 const ObjectSetPosition &object_set_position) {
169 os << "[positions=[";
171 for (auto &object_position : object_set_position.object_positions) {
172 os << delim << object_position;
179 std::ostream &operator<<(std::ostream &os, const Client &client) {
180 os << "[id=" << client.id << ", "
181 << "commit_position=" << client.commit_position << ", "
182 << "state=" << client.state << "]";
186 std::ostream &operator<<(std::ostream &os, const Tag &tag) {
187 os << "[tid=" << tag.tid << ", "
188 << "tag_class=" << tag.tag_class << ", "
190 tag.data.hexdump(os);
195 } // namespace journal