18 #include "mongo/config.h"
22 #include "mongo/platform/endian.h"
24 #if __cplusplus >= 201103L
25 #include <type_traits>
32 typedef const char* bytes_type;
36 bytes_type view(std::size_t offset = 0)
const {
37 return _bytes + offset;
41 const ConstDataView& readNative(T* t,
size_t offset = 0)
const {
42 #if MONGO_HAVE_STD_IS_TRIVIALLY_COPYABLE
43 static_assert(std::is_trivially_copyable<T>::value,
44 "Type for DataView::readNative must be trivially copyable");
46 std::memcpy(t, view(offset),
sizeof(*t));
51 T readNative(std::size_t offset = 0)
const {
53 readNative(&t, offset);
58 T readLE(std::size_t offset = 0)
const {
59 return endian::littleToNative(readNative<T>(offset));
63 T readBE(std::size_t offset = 0)
const {
64 return endian::bigToNative(readNative<T>(offset));
73 typedef char* bytes_type;
77 bytes_type view(std::size_t offset = 0)
const {
80 return const_cast<bytes_type
>(ConstDataView::view(offset));
84 DataView& writeNative(
const T& value, std::size_t offset = 0) {
85 #if MONGO_HAVE_STD_IS_TRIVIALLY_COPYABLE
86 static_assert(std::is_trivially_copyable<T>::value,
87 "Type for DataView::writeNative must be trivially copyable");
89 std::memcpy(view(offset), &value,
sizeof(value));
94 DataView& writeLE(
const T& value, std::size_t offset = 0) {
95 return writeNative(endian::nativeToLittle(value), offset);
99 DataView& writeBE(
const T& value, std::size_t offset = 0) {
100 return writeNative(endian::nativeToBig(value), offset);
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
Definition: data_view.h:30
Definition: data_view.h:71