Pottu
ebyedataheader.hpp
Go to the documentation of this file.
1 
7 #ifndef H_POTTU_EBYEDATAHEADER
8 #define H_POTTU_EBYEDATAHEADER
9 
10 
11 #include <cstdint>
12 #include <cstring>
13 #include <cctype>
14 #include <iostream>
15 
16 namespace pottu {
17 
21  {
22  char id[8];
23  uint32_t sequence;
24  uint16_t stream;
25  uint16_t tape;
26  uint16_t myEndian;
27  uint16_t dataEndian;
28  uint32_t dataLen;
29 
30 
40  static ebyedataheader_t createFromMemory( const char *p ) noexcept {
41  ebyedataheader_t ret;
42  if( sizeof(ebyedataheader_t) == 24 ) {
43  // Faster version. It is very likely that this is the one
44  // most compilers will do.
45  std::memcpy( (void *)&ret, p, 24 );
46  } else {
47  // Support for unusual memory layout
48  std::memcpy( &ret.id, (const char *)p + 0, 8 );
49  std::memcpy( &ret.sequence, (const char *)p + 8, 4 );
50  std::memcpy( &ret.stream, (const char *)p + 12, 2 );
51  std::memcpy( &ret.tape, (const char *)p + 14, 2 );
52  std::memcpy( &ret.myEndian, (const char *)p + 16, 2 );
53  std::memcpy( &ret.dataEndian, (const char *)p + 18, 2 );
54  std::memcpy( &ret.dataLen, (const char *)p + 20, 4 );
55  }
56  return ret;
57  }
58 
59 
60  friend std::ostream &operator<<(std::ostream &os, const ebyedataheader_t &h) {
61  os << "(";
62 
63  for( int i = 0; i < 8; ++i ) {
64  os << (int)h.id[i] << "\"";
65  if( isascii( h.id[i] ) )
66  os << h.id[i];
67  os << "\" ";
68  }
69 
70  os << h.sequence << ","
71  << h.stream << ","
72  << h.tape << ","
73  << h.myEndian << ","
74  << h.dataEndian << ","
75  << h.dataLen << ")";
76  return (os);
77  }
78 
79 
87  bool isValid() const noexcept {
88  return stream == 1 && myEndian == 1 && dataEndian == 1
89  && strncmp((const char *)&id, "EBYEDATA", 8) == 0;
90  }
91  };
92 
93 
94 }
95 
96 
97 #endif
Definition: mainpage.dox:6
Struct defining the block header in the tdr file.
Definition: ebyedataheader.hpp:21
bool isValid() const noexcept
Checks that header is valid-.
Definition: ebyedataheader.hpp:87
static ebyedataheader_t createFromMemory(const char *p) noexcept
Creates ebyedataheader_t from a memory buffer.
Definition: ebyedataheader.hpp:40