Bug 1600800: Force device pixels to be 1.0 for wpt reftests r=jgraham
[gecko.git] / toolkit / recordreplay / BufferStream.h
blob2c12e67bc1a76299c85bcfced2aa5bd029d7c739
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_recordreplay_BufferStream_h
8 #define mozilla_recordreplay_BufferStream_h
10 #include "InfallibleVector.h"
12 namespace mozilla {
13 namespace recordreplay {
15 // BufferStream provides similar functionality to Stream in File.h, allowing
16 // reading or writing to a stream of data backed by an in memory buffer instead
17 // of data stored on disk.
18 class BufferStream {
19 InfallibleVector<char>* mOutput;
21 const char* mInput;
22 size_t mInputSize;
24 public:
25 BufferStream(const char* aInput, size_t aInputSize)
26 : mOutput(nullptr), mInput(aInput), mInputSize(aInputSize) {}
28 explicit BufferStream(InfallibleVector<char>* aOutput)
29 : mOutput(aOutput), mInput(nullptr), mInputSize(0) {}
31 void WriteBytes(const void* aData, size_t aSize) {
32 MOZ_RELEASE_ASSERT(mOutput);
33 mOutput->append((char*)aData, aSize);
36 void WriteScalar(size_t aValue) { WriteBytes(&aValue, sizeof(aValue)); }
38 void ReadBytes(void* aData, size_t aSize) {
39 if (aSize) {
40 MOZ_RELEASE_ASSERT(mInput);
41 MOZ_RELEASE_ASSERT(aSize <= mInputSize);
42 memcpy(aData, mInput, aSize);
43 mInput += aSize;
44 mInputSize -= aSize;
48 size_t ReadScalar() {
49 size_t rv;
50 ReadBytes(&rv, sizeof(rv));
51 return rv;
54 bool IsEmpty() {
55 MOZ_RELEASE_ASSERT(mInput);
56 return mInputSize == 0;
60 } // namespace recordreplay
61 } // namespace mozilla
63 #endif // mozilla_recordreplay_BufferStream_h