]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/onode.cc
a8b925b7014884cd657c69485ba6a9a399949298
[ceph.git] / ceph / src / crimson / os / seastore / onode.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "onode.h"
5 #include "include/encoding.h"
6
7 namespace crimson::os::seastore {
8
9 size_t Onode::size() const
10 {
11 return ceph::encoded_sizeof(*this);
12 }
13
14 void Onode::encode(void* buffer, size_t len)
15 {
16 struct [[gnu::packed]] encoded_t {
17 uint8_t struct_v;
18 uint8_t struct_compat;
19 uint32_t struct_len;
20 uint32_t len;
21 char data[];
22 };
23 auto p = reinterpret_cast<encoded_t*>(buffer);
24 assert(std::numeric_limits<uint16_t>::max() >= size());
25 assert(len >= size());
26 p->struct_v = 1;
27 p->struct_compat = 1;
28 p->struct_len = sizeof(encoded_t) + payload.size();
29 p->len = payload.size();
30 std::memcpy(p->data, payload.data(), payload.size());
31 }
32
33 bool operator==(const Onode& lhs, const Onode& rhs)
34 {
35 return lhs.get() == rhs.get();
36 }
37
38 std::ostream& operator<<(std::ostream &out, const Onode &rhs)
39 {
40 return out << rhs.get();
41 }
42
43 }
44