AJA NTV2 SDK  18.1.0.2439
NTV2 SDK 18.1.0.2439
ntv2nubtypes.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef __NTV2NUBTYPES_H
9 #define __NTV2NUBTYPES_H
10 
11 #include "ntv2endian.h"
12 #include <vector>
13 
14 #if !defined(NTV2_DEPRECATE_16_3)
15  // In SDK 16.3 or later, client/server RPC implementations are plugins, each with their own protocols/versioning
17 #endif // !defined(NTV2_DEPRECATE_16_3)
18 
19 typedef std::vector<uint8_t> RPCBlob;
20 
21 namespace ntv2nub
22 {
23  const bool kDisableByteSwap (true);
24  const bool kEnableByteSwapIfNeeded (false);
25 
30 
37  inline void PUSHU8(const uint8_t val, RPCBlob & blob)
38  {
39  blob.push_back(val);
40  }
41 
49  inline void PUSHU16(const uint16_t val, RPCBlob & blob, const bool dontSwap = false)
50  {
51  const uint16_t _u16 ((NTV2HostIsBigEndian || dontSwap) ? val : NTV2EndianSwap16HtoB(val));
52  const UByte * _pU16 (reinterpret_cast<const UByte*>(&_u16));
53  blob.push_back(_pU16[0]); blob.push_back(_pU16[1]);
54  }
55 
63  inline void PUSHU32(const uint32_t val, RPCBlob & blob, const bool dontSwap = false)
64  {
65  const uint32_t _u32 ((NTV2HostIsBigEndian || dontSwap) ? val : NTV2EndianSwap32HtoB(val));
66  const UByte * _pU32 (reinterpret_cast<const UByte*>(&_u32));
67  blob.push_back(_pU32[0]); blob.push_back(_pU32[1]);
68  blob.push_back(_pU32[2]); blob.push_back(_pU32[3]);
69  }
70 
78  inline void PUSHU64(const uint64_t val, RPCBlob & blob, const bool dontSwap = false)
79  {
80  const uint64_t _u64 ((NTV2HostIsBigEndian || dontSwap) ? val : NTV2EndianSwap64HtoB(val));
81  const UByte * _pU64 (reinterpret_cast<const UByte*>(&_u64));
82  blob.push_back(_pU64[0]); blob.push_back(_pU64[1]);
83  blob.push_back(_pU64[2]); blob.push_back(_pU64[3]);
84  blob.push_back(_pU64[4]); blob.push_back(_pU64[5]);
85  blob.push_back(_pU64[6]); blob.push_back(_pU64[7]);
86  }
88 
89 #if defined(_DEBUG)
90  #define NTV2_NUB_RGCHK(_cnt_) if (inOutNdx + (_cnt_) > blob.size()) \
91  return false;
92 #else
93  #define NTV2_NUB_RGCHK(_cnt_)
94 #endif
95 
100 
110  inline bool POPU8 (uint8_t & outVal, const RPCBlob & blob, std::size_t & inOutNdx)
111  {
112  NTV2_NUB_RGCHK(1)
113  outVal = blob.at(inOutNdx++);
114  return true;
115  }
116 
128  inline bool POPU16 (uint16_t & outVal, const RPCBlob & blob, std::size_t & inOutNdx, const bool dontSwap = false)
129  {
130  uint16_t _u16(0);
131  UByte * _pU8(reinterpret_cast<UByte*>(&_u16));
132  NTV2_NUB_RGCHK(2)
133  _pU8[0] = blob.at(inOutNdx++); _pU8[1] = blob.at(inOutNdx++);
134  outVal = (NTV2HostIsBigEndian || dontSwap) ? _u16 : NTV2EndianSwap16BtoH(_u16);
135  return true;
136  }
137 
149  inline bool POPU32 (uint32_t & outVal, const RPCBlob & blob, std::size_t & inOutNdx, const bool dontSwap = false)
150  {
151  uint32_t _u32(0);
152  UByte * _pU8(reinterpret_cast<UByte*>(&_u32));
153  NTV2_NUB_RGCHK(4)
154  _pU8[0] = blob.at(inOutNdx++); _pU8[1] = blob.at(inOutNdx++);
155  _pU8[2] = blob.at(inOutNdx++); _pU8[3] = blob.at(inOutNdx++);
156  outVal = (NTV2HostIsBigEndian || dontSwap) ? _u32 : NTV2EndianSwap32BtoH(_u32);
157  return true;
158  }
159 
171  inline bool POPU64 (uint64_t & outVal, const RPCBlob & blob, std::size_t & inOutNdx, const bool dontSwap = false)
172  {
173  uint64_t _u64(0);
174  UByte * _pU8(reinterpret_cast<UByte*>(&_u64));
175  NTV2_NUB_RGCHK(8)
176  _pU8[0] = blob.at(inOutNdx++); _pU8[1] = blob.at(inOutNdx++);
177  _pU8[2] = blob.at(inOutNdx++); _pU8[3] = blob.at(inOutNdx++);
178  _pU8[4] = blob.at(inOutNdx++); _pU8[5] = blob.at(inOutNdx++);
179  _pU8[6] = blob.at(inOutNdx++); _pU8[7] = blob.at(inOutNdx++);
180  outVal = (NTV2HostIsBigEndian || dontSwap) ? _u64 : NTV2EndianSwap64BtoH(_u64);
181  return true;
182  }
184 
185 } // namespace ntv2nub
186 
187 #endif // __NTV2NUBTYPES_H
#define NTV2HostIsBigEndian
Definition: ntv2endian.h:58
void PUSHU32(const uint32_t val, RPCBlob &blob, const bool dontSwap=false)
Pushes a 32-bit value onto the given byte sequence.
Definition: ntv2nubtypes.h:63
#define NTV2EndianSwap32BtoH(__val__)
Definition: ntv2endian.h:63
Defines a number of handy byte-swapping macros.
bool POPU8(uint8_t &outVal, const RPCBlob &blob, std::size_t &inOutNdx)
Pops an 8-bit value off the given byte sequence at the given zero-based index position.
Definition: ntv2nubtypes.h:110
ULWord NTV2NubProtocolVersion
Definition: ntv2nubtypes.h:16
uint32_t ULWord
Definition: ajatypes.h:236
const bool kDisableByteSwap(true)
void PUSHU8(const uint8_t val, RPCBlob &blob)
Pushes an 8-bit value onto the given byte sequence.
Definition: ntv2nubtypes.h:37
#define NTV2EndianSwap64HtoB(__val__)
Definition: ntv2endian.h:66
#define NTV2EndianSwap64BtoH(__val__)
Definition: ntv2endian.h:65
void PUSHU16(const uint16_t val, RPCBlob &blob, const bool dontSwap=false)
Pushes a 16-bit value onto the given byte sequence.
Definition: ntv2nubtypes.h:49
uint8_t UByte
Definition: ajatypes.h:231
#define NTV2EndianSwap32HtoB(__val__)
Definition: ntv2endian.h:64
#define NTV2EndianSwap16BtoH(__val__)
Definition: ntv2endian.h:61
const bool kEnableByteSwapIfNeeded(false)
std::vector< uint8_t > RPCBlob
Definition: ntv2nubtypes.h:19
#define NTV2EndianSwap16HtoB(__val__)
Definition: ntv2endian.h:62
bool POPU32(uint32_t &outVal, const RPCBlob &blob, std::size_t &inOutNdx, const bool dontSwap=false)
Pops a 32-bit value off the given byte sequence at the given zero-based index position.
Definition: ntv2nubtypes.h:149
bool POPU64(uint64_t &outVal, const RPCBlob &blob, std::size_t &inOutNdx, const bool dontSwap=false)
Pops a 64-bit value off the given byte sequence at the given zero-based index position.
Definition: ntv2nubtypes.h:171
bool POPU16(uint16_t &outVal, const RPCBlob &blob, std::size_t &inOutNdx, const bool dontSwap=false)
Pops a 16-bit value off the given byte sequence at the given zero-based index position.
Definition: ntv2nubtypes.h:128
#define NTV2_NUB_RGCHK(_cnt_)
Definition: ntv2nubtypes.h:93
void PUSHU64(const uint64_t val, RPCBlob &blob, const bool dontSwap=false)
Pushes a 64-bit value onto the given byte sequence.
Definition: ntv2nubtypes.h:78