Leviathan  0.8.0.0
Leviathan game engine
Leviathan::XiphLacing Class Reference

Public Member Functions

 XiphLacing (const uint8_t *data, size_t length)
 

Public Attributes

int ItemCount
 
std::vector< size_t > ItemSizes
 
int LacedHeaderLenght
 The total lacing header size, used to get from start of the data to the first object. More...
 

Detailed Description

Xiph lacing handling First is the item count - 1 (so 0 means there's 1 item). Then there is "item count - 1" number of object sizes. The object sizes are encoded as bytes with the first bite less than 255 ending the number. The last object's size is not encoded (it takes up the rest of the space after the other sizes are subtrackted), this is why the item count - 1 is the number in the data.

Definition at line 299 of file MatroskaParser.cpp.

Constructor & Destructor Documentation

◆ XiphLacing()

Leviathan::XiphLacing::XiphLacing ( const uint8_t *  data,
size_t  length 
)
inline

Definition at line 301 of file MatroskaParser.cpp.

302  {
303  if(length < 1)
304  throw InvalidArgument("data length is 0");
305 
306  int count = data[0];
307  size_t readOffset = 1;
308 
309  // The last item is implicit
310  ItemCount = count + 1;
311 
312  size_t otherObjectSizes = 0;
313 
314  // Read the object lengths
315  for(int i = 0; i < count; ++i) {
316  size_t currentLength = 0;
317  int byte;
318  do {
319  if(readOffset >= length)
320  throw InvalidArgument("data ended while parsing laced lengths");
321 
322  byte = data[readOffset];
323  ++readOffset;
324 
325  currentLength += byte;
326 
327  } while(byte >= 255);
328 
329  ItemSizes.push_back(currentLength);
330  otherObjectSizes += currentLength;
331  }
332 
333  // Header ended
334  LacedHeaderLenght = static_cast<int>(readOffset);
335 
336  // The last object is the rest of the length
337  const int64_t lastObjectSize = length - LacedHeaderLenght - otherObjectSizes;
338 
339  if(lastObjectSize <= 0)
340  throw InvalidArgument(
341  "laced data length left for last item is zero or negative: " +
342  std::to_string(lastObjectSize));
343 
344  ItemSizes.push_back(lastObjectSize);
345  }
std::vector< size_t > ItemSizes
int LacedHeaderLenght
The total lacing header size, used to get from start of the data to the first object.

Member Data Documentation

◆ ItemCount

int Leviathan::XiphLacing::ItemCount

Definition at line 347 of file MatroskaParser.cpp.

◆ ItemSizes

std::vector<size_t> Leviathan::XiphLacing::ItemSizes

Definition at line 348 of file MatroskaParser.cpp.

◆ LacedHeaderLenght

int Leviathan::XiphLacing::LacedHeaderLenght

The total lacing header size, used to get from start of the data to the first object.

Definition at line 351 of file MatroskaParser.cpp.


The documentation for this class was generated from the following file: