Overte C++ Documentation
StreamHelpers.h
1 //
2 // Created by Bradley Austin Davis 2015/07/16
3 // Copyright 2014 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_StreamHelpers_h
11 #define hifi_StreamHelpers_h
12 
13 #include <QIODevice>
14 #include <QBuffer>
15 
16 // Helper functions for reading binary data from an IO device
17 template<class T>
18 inline void readStream(QIODevice& in, T& t) {
19  in.read((char*) &t, sizeof(t));
20 }
21 
22 template<typename T, size_t N>
23 inline void readStream(QIODevice& in, T (&t)[N]) {
24  in.read((char*) t, N);
25 }
26 
27 template<class T, size_t N>
28 inline void fillBuffer(QBuffer& buffer, T (&t)[N]) {
29  buffer.setData((const char*) t, N);
30 }
31 
32 #endif