JayBeams  0.1
Another project to have fun coding.
base_decoders.hpp
Go to the documentation of this file.
1 #ifndef jb_itch5_base_decoders_hpp
2 #define jb_itch5_base_decoders_hpp
3 
4 #include <jb/itch5/decoder.hpp>
5 #include <cstdint>
6 
7 namespace jb {
8 namespace itch5 {
9 
10 /// Specialize jb::itch5::decoder for 1-byte integer (or character) fields.
11 template <bool validate>
12 struct decoder<validate, std::uint8_t> {
13  /// Please see the generic documentation for jb::itch5::decoder<>::r()
14  static std::uint8_t r(std::size_t size, void const* msg, std::size_t offset) {
15  check_offset<validate>("std::uint8_t", size, offset, 1);
16  return static_cast<std::uint8_t const*>(msg)[offset];
17  }
18 };
19 
20 /// Specialize jb::itch5::decoder for 2-byte integer fields.
21 template <bool validate>
22 struct decoder<validate, std::uint16_t> {
23  /// Please see the generic documentation for jb::itch5::decoder<>::r()
24  static std::uint16_t
25  r(std::size_t size, void const* msg, std::size_t offset) {
26  check_offset<validate>("std::uint16_t", size, offset, 2);
27  std::uint8_t hi = decoder<false, std::uint8_t>::r(size, msg, offset);
28  std::uint8_t lo = decoder<false, std::uint8_t>::r(size, msg, offset + 1);
29  return std::uint16_t(hi) << 8 | lo;
30  }
31 };
32 
33 /// Specialize jb::itch5::decoder for 4-byte integer fields.
34 template <bool validate>
35 struct decoder<validate, std::uint32_t> {
36  /// Please see the generic documentation for jb::itch5::decoder<>::r()
37  static std::uint32_t
38  r(std::size_t size, void const* msg, std::size_t offset) {
39  check_offset<validate>("std::uint32_t", size, offset, 4);
40  std::uint16_t hi = decoder<false, std::uint16_t>::r(size, msg, offset);
41  std::uint16_t lo = decoder<false, std::uint16_t>::r(size, msg, offset + 2);
42  return std::uint32_t(hi) << 16 | lo;
43  }
44 };
45 
46 /// Specialize jb::itch5::decoder for 4-byte integer fields.
47 template <bool validate>
48 struct decoder<validate, std::uint64_t> {
49  /// Please see the generic documentation for jb::itch5::decoder<>::r()
50  static std::uint64_t
51  r(std::size_t size, void const* msg, std::size_t offset) {
52  check_offset<validate>("std::uint32_t", size, offset, 8);
53  std::uint32_t hi = decoder<false, std::uint32_t>::r(size, msg, offset);
54  std::uint32_t lo = decoder<false, std::uint32_t>::r(size, msg, offset + 4);
55  return std::uint64_t(hi) << 32 | lo;
56  }
57 };
58 
59 } // namespace itch5
60 } // namespace jb
61 
62 #endif // jb_itch5_base_decoders_hpp
static T r(std::size_t size, void const *msg, std::size_t offset)
Read a single message or field.
static std::uint16_t r(std::size_t size, void const *msg, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
STL namespace.
static std::uint32_t r(std::size_t size, void const *msg, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
static std::uint8_t r(std::size_t size, void const *msg, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
Define the interface to decode ITCH-5.0 messages and message fields.
Definition: decoder.hpp:24
static std::uint64_t r(std::size_t size, void const *msg, std::size_t offset)
Please see the generic documentation for jb::itch5::decoder<>::r()
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7