Support: Functions for consuming endian specific data from a buffer.
authorJustin Bogner <mail@justinbogner.com>
Tue, 25 Mar 2014 01:04:44 +0000 (01:04 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 25 Mar 2014 01:04:44 +0000 (01:04 +0000)
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

include/llvm/Support/Endian.h

index 81690605e87d391143d8d0f658065e77b5b74f91..2c5ab74aa36744dbd012770813f72d5d5e01b3ce 100644 (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,