summaryrefslogtreecommitdiffstats
path: root/src/crimson/os/seastore/onode.cc
blob: a8b925b7014884cd657c69485ba6a9a399949298 (plain)
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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "onode.h"
#include "include/encoding.h"

namespace crimson::os::seastore {

size_t Onode::size() const
{
  return ceph::encoded_sizeof(*this);
}

void Onode::encode(void* buffer, size_t len)
{
  struct [[gnu::packed]] encoded_t {
    uint8_t struct_v;
    uint8_t struct_compat;
    uint32_t struct_len;
    uint32_t len;
    char data[];
  };
  auto p = reinterpret_cast<encoded_t*>(buffer);
  assert(std::numeric_limits<uint16_t>::max() >= size());
  assert(len >= size());
  p->struct_v = 1;
  p->struct_compat = 1;
  p->struct_len = sizeof(encoded_t) + payload.size();
  p->len = payload.size();
  std::memcpy(p->data, payload.data(), payload.size());
}

bool operator==(const Onode& lhs, const Onode& rhs)
{
  return lhs.get() == rhs.get();
}

std::ostream& operator<<(std::ostream &out, const Onode &rhs)
{
  return out << rhs.get();
}

}