proxygen
fizz::test::BlockWriter Struct Reference

Public Member Functions

size_t copy (uint8_t *out, const uint8_t *in, size_t len)
 

Public Attributes

size_t internalOffset = 0
 
uint8_t block [8] = {0}
 

Detailed Description

Definition at line 94 of file IOBufUtilTest.cpp.

Member Function Documentation

size_t fizz::test::BlockWriter::copy ( uint8_t out,
const uint8_t in,
size_t  len 
)
inline

Definition at line 95 of file IOBufUtilTest.cpp.

Referenced by fizz::test::TEST().

95  {
96  if (len + internalOffset < 8) {
97  // still not enough for a block
98  memcpy(block + internalOffset, in, len);
99  internalOffset += len;
100  // nothing copied to out
101  return 0;
102  }
103  size_t outOffset = 0;
104  // need to copy in block chunks
105  auto numToWrite = 8 * ((internalOffset + len) / 8);
106  if (internalOffset > 0) {
107  memcpy(out, block, internalOffset);
108  outOffset += internalOffset;
109  numToWrite -= internalOffset;
110  internalOffset = 0;
111  }
112 
113  // copy the rest
114  memcpy(out + outOffset, in, numToWrite);
115  // check if we need to internal buffer anything left
116  if (len > numToWrite) {
117  auto numToBuf = len - numToWrite;
118  DCHECK(numToBuf < 8);
119  memcpy(block, in + numToWrite, numToBuf);
120  internalOffset = numToBuf;
121  }
122  return numToWrite + outOffset;
123  }

Member Data Documentation

uint8_t fizz::test::BlockWriter::block[8] = {0}

Definition at line 126 of file IOBufUtilTest.cpp.

size_t fizz::test::BlockWriter::internalOffset = 0

Definition at line 125 of file IOBufUtilTest.cpp.


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