1*fb07ece0SStephan Aßmus /* 2*fb07ece0SStephan Aßmus * Copyright 2006, Haiku. All rights reserved. 3*fb07ece0SStephan Aßmus * Distributed under the terms of the MIT License. 4*fb07ece0SStephan Aßmus * 5*fb07ece0SStephan Aßmus * Authors: 6*fb07ece0SStephan Aßmus * Stephan Aßmus <superstippi@gmx.de> 7*fb07ece0SStephan Aßmus */ 8*fb07ece0SStephan Aßmus 9*fb07ece0SStephan Aßmus #ifndef LITTLE_ENDIAN_BUFFER_H 10*fb07ece0SStephan Aßmus #define LITTLE_ENDIAN_BUFFER_H 11*fb07ece0SStephan Aßmus 12*fb07ece0SStephan Aßmus #include <SupportDefs.h> 13*fb07ece0SStephan Aßmus 14*fb07ece0SStephan Aßmus class LittleEndianBuffer { 15*fb07ece0SStephan Aßmus public: 16*fb07ece0SStephan Aßmus LittleEndianBuffer(); 17*fb07ece0SStephan Aßmus LittleEndianBuffer(size_t size); 18*fb07ece0SStephan Aßmus LittleEndianBuffer(uint8* buffer, 19*fb07ece0SStephan Aßmus size_t size); 20*fb07ece0SStephan Aßmus ~LittleEndianBuffer(); 21*fb07ece0SStephan Aßmus 22*fb07ece0SStephan Aßmus bool Write(uint8 value); 23*fb07ece0SStephan Aßmus bool Write(uint16 value); 24*fb07ece0SStephan Aßmus bool Write(uint32 value); 25*fb07ece0SStephan Aßmus bool Write(float value); 26*fb07ece0SStephan Aßmus bool Write(double value); 27*fb07ece0SStephan Aßmus 28*fb07ece0SStephan Aßmus bool Write(const LittleEndianBuffer& other); 29*fb07ece0SStephan Aßmus bool Write(const uint8* buffer, size_t bytes); 30*fb07ece0SStephan Aßmus 31*fb07ece0SStephan Aßmus bool Read(uint8& value); 32*fb07ece0SStephan Aßmus bool Read(uint16& value); 33*fb07ece0SStephan Aßmus bool Read(uint32& value); 34*fb07ece0SStephan Aßmus bool Read(float& value); 35*fb07ece0SStephan Aßmus bool Read(double& value); 36*fb07ece0SStephan Aßmus bool Read(LittleEndianBuffer& other, size_t bytes); 37*fb07ece0SStephan Aßmus 38*fb07ece0SStephan Aßmus void Skip(size_t bytes); 39*fb07ece0SStephan Aßmus 40*fb07ece0SStephan Aßmus uint8* Buffer() const 41*fb07ece0SStephan Aßmus { return fBuffer; } 42*fb07ece0SStephan Aßmus size_t SizeUsed() const 43*fb07ece0SStephan Aßmus { return fHandle - fBuffer; } 44*fb07ece0SStephan Aßmus 45*fb07ece0SStephan Aßmus void Reset(); 46*fb07ece0SStephan Aßmus 47*fb07ece0SStephan Aßmus private: 48*fb07ece0SStephan Aßmus void _SetSize(size_t size); 49*fb07ece0SStephan Aßmus 50*fb07ece0SStephan Aßmus uint8* fBuffer; 51*fb07ece0SStephan Aßmus uint8* fHandle; 52*fb07ece0SStephan Aßmus uint8* fBufferEnd; 53*fb07ece0SStephan Aßmus size_t fSize; 54*fb07ece0SStephan Aßmus bool fOwnsBuffer; 55*fb07ece0SStephan Aßmus }; 56*fb07ece0SStephan Aßmus 57*fb07ece0SStephan Aßmus #endif // LITTLE_ENDIAN_BUFFER_H 58