proxygen
folly::io::compression::detail Namespace Reference

Functions

template<typename T >
std::enable_if< std::is_unsigned< T >::value, bool >::type dataStartsWithLE (const IOBuf *data, T prefix, uint64_t n=sizeof(T))
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, std::string >::type prefixToStringLE (T prefix, uint64_t n=sizeof(T))
 

Function Documentation

template<typename T >
std::enable_if<std::is_unsigned<T>::value, bool>::type folly::io::compression::detail::dataStartsWithLE ( const IOBuf data,
T  prefix,
uint64_t  n = sizeof(T) 
)

Reads sizeof(T) bytes, and returns false if not enough bytes are available. Returns true if the first n bytes are equal to prefix when interpreted as a little endian T.

Definition at line 40 of file Utils.h.

References string, folly::T, type, value, and folly::value().

Referenced by folly::io::StreamCodec::doUncompress().

40  {
41  DCHECK_GT(n, 0);
42  DCHECK_LE(n, sizeof(T));
43  T value;
44  Cursor cursor{data};
45  if (!cursor.tryReadLE(value)) {
46  return false;
47  }
48  const T mask = n == sizeof(T) ? T(-1) : (T(1) << (8 * n)) - 1;
49  return prefix == (value & mask);
50 }
#define T(v)
Definition: http_parser.c:233
bool prefix(Cursor &c, uint32_t expected)
static const char *const value
Definition: Conv.cpp:50
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
template<typename T >
std::enable_if<std::is_arithmetic<T>::value, std::string>::type folly::io::compression::detail::prefixToStringLE ( T  prefix,
uint64_t  n = sizeof(T) 
)

Definition at line 54 of file Utils.h.

References folly::Endian::little(), string, and folly::T.

Referenced by folly::io::StreamCodec::doUncompress().

54  {
55  DCHECK_GT(n, 0);
56  DCHECK_LE(n, sizeof(T));
57  prefix = Endian::little(prefix);
58  std::string result;
59  result.resize(n);
60  memcpy(&result[0], &prefix, n);
61  return result;
62 }
#define T(v)
Definition: http_parser.c:233
bool prefix(Cursor &c, uint32_t expected)
const char * string
Definition: Conv.cpp:212