DP3
BlobHeader.h
Go to the documentation of this file.
1 // BlobHeader.h: Standard header for a blob
2 //
3 // Copyright (C) 2020 ASTRON (Netherlands Institute for Radio Astronomy)
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #ifndef LOFAR_BLOB_BLOBHEADER_H
7 #define LOFAR_BLOB_BLOBHEADER_H
8 
9 #include "common/DataConvert.h"
10 
11 #include <cstring>
12 
13 namespace dp3 {
14 namespace blob {
15 
18 
20 
69 
70 class BlobHeader {
71  friend class BlobOStream;
72  friend class BlobIStream;
73 
74  public:
76  BlobHeader(int version = 0, unsigned int level = 0);
77 
80  return dp3::common::DataFormat(itsDataFormat);
81  }
82 
85 
87  int getVersion() const {
88  return (mustConvert()
90  : itsVersion);
91  }
92 
94  uint64_t getLength() const {
95  return (mustConvert() ? dp3::common::dataConvert(getDataFormat(), itsLength)
96  : itsLength);
97  }
98 
100  void setLength(uint64_t length) { itsLength = length; }
101 
104  bool mustConvert() const {
105  return itsDataFormat != dp3::common::dataFormat();
106  }
107 
109  unsigned int lengthOffset() const { return 0; }
110 
112  unsigned int getNameLength() const { return itsNameLength; }
113 
115  static uint32_t bobMagicValue() { return 0xbebebebe; }
116 
118  static uint32_t eobMagicValue() { return 0xbfbfbfbf; }
119 
120  bool checkMagicValue() const { return itsMagicValue == bobMagicValue(); }
121 
123  unsigned int getHeaderLength() const {
124  return sizeof(BlobHeader) + itsNameLength;
125  }
126 
127  private:
128  uint64_t itsLength;
129  uint32_t itsMagicValue;
130  char itsVersion;
131  char itsDataFormat;
132  unsigned char itsLevel;
133  unsigned char itsNameLength;
134 };
135 
137 
138 } // namespace blob
139 } // namespace dp3
140 
141 #endif
Standard header for a blob.
Definition: BlobHeader.h:70
bool mustConvert() const
Definition: BlobHeader.h:104
void setLocalDataFormat()
Set the data format to local. Useful after data is converted in place.
unsigned int getNameLength() const
Get the name length.
Definition: BlobHeader.h:112
unsigned int getHeaderLength() const
Get the length of the total header (thus including objecttype).
Definition: BlobHeader.h:123
BlobHeader(int version=0, unsigned int level=0)
Construct for the given name and version.
bool checkMagicValue() const
Definition: BlobHeader.h:120
uint64_t getLength() const
Get the length of the blob. Data will be converted if needed.
Definition: BlobHeader.h:94
int getVersion() const
Get the version. Data will be converted if needed.
Definition: BlobHeader.h:87
static uint32_t eobMagicValue()
Get the end-of-blob magic value.
Definition: BlobHeader.h:118
static uint32_t bobMagicValue()
Get the begin-of-blob magic value.
Definition: BlobHeader.h:115
unsigned int lengthOffset() const
Get the offset of the length.
Definition: BlobHeader.h:109
dp3::common::DataFormat getDataFormat() const
Get the data format.
Definition: BlobHeader.h:79
void setLength(uint64_t length)
Set the length of the blob.
Definition: BlobHeader.h:100
Input stream for a blob.
Definition: BlobIStream.h:43
Output stream for a blob.
Definition: BlobOStream.h:40
void dataConvert(DataFormat, char *inout, unsigned int nrval)
Definition: DataConvert.h:175
DataFormat dataFormat()
Get the endian type on this machine.
Definition: DataFormat.h:27
DataFormat
This file defines an enum for the possible machine data formats.
Definition: DataFormat.h:24
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53