Welcome to mirror list, hosted at ThFree Co, Russian Federation.

serdes_binary_header.hpp « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54a4d0a09a3ffe2b0b97528369d4abc7fd5b2957 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include "coding/reader.hpp"
#include "coding/write_to_sink.hpp"

#include <cstdint>

namespace coding
{
namespace binary
{
struct HeaderSizeOfVisitor
{
  void operator()(uint64_t v, char const * /* name */ = nullptr) { m_size += sizeof(v); }

  template <typename R>
  void operator()(R & r, char const * /* name */ = nullptr)
  {
    r.Visit(*this);
  }

  uint64_t m_size = 0;
};

template <typename Sink>
struct HeaderSerVisitor
{
  HeaderSerVisitor(Sink & sink) : m_sink(sink) {}

  void operator()(uint64_t v, char const * /* name */ = nullptr) { WriteToSink(m_sink, v); }

  template <typename R>
  void operator()(R & r, char const * /* name */ = nullptr)
  {
    r.Visit(*this);
  }

  Sink & m_sink;
};

template <typename Source>
struct HeaderDesVisitor
{
  HeaderDesVisitor(Source & source): m_source(source) {}

  void operator()(uint64_t & v, char const * /* name */ = nullptr)
  {
    v = ReadPrimitiveFromSource<uint64_t>(m_source);
  }

  template <typename R>
  void operator()(R & r, char const * /* name */ = nullptr)
  {
    r.Visit(*this);
  }

  Source & m_source;
};
}  // namespace binary
}  // namespace coding