Support: Functions for consuming endian specific data from a buffer.

This adds a function to Endian.h that reads from and updates a pointer
into a buffer with endian specific data. This is more convenient for
stream-like reading of data than endian::read.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204693 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner 2014-03-25 01:04:44 +00:00
parent 692d1830f3
commit 93065647b8

View File

@ -56,6 +56,15 @@ inline value_type read(const void *memory) {
return byte_swap<value_type, endian>(ret);
}
/// Read a value of a particular endianness from a buffer, and increment the
/// buffer past that value.
template<typename value_type, endianness endian, std::size_t alignment>
inline value_type readNext(const unsigned char *&memory) {
value_type ret = read<value_type, endian, alignment>(memory);
memory += sizeof(value_type);
return ret;
}
/// Write a value to memory with a particular endianness.
template<typename value_type,
endianness endian,