4 #include <condition_variable>
11 namespace dangerous {
namespace snmp {
91 void copyTo( std::vector<char>& buffer )
const;
98 void copyTo( std::string& buffer )
const;
107 int compareWith(
const char* buffer,
unsigned int bufferLength )
const;
200 bool readBytes(
char* buffer,
unsigned int bufferSize,
unsigned int& bytesRead );
221 bool writeBytes(
const char* buffer,
unsigned int bufferSize,
unsigned int& bytesWritten );
331 bool grow(
unsigned int increment );
bool writeByte(char byte)
This writes a byte to the ByteStream.
ByteStream()
Default constructor; this creates a new, empty ByteStream.
A ByteStream is an object that is basically a big wrapper around a character buffer.
Definition: bytestream.hpp:30
void readTimeout(const std::chrono::milliseconds &timeout)
This sets the read timeout for the stream.
Definition: bytestream.hpp:148
bool peekByte(char &byte)
This reads a byte from the ByteStream.
bool _isErrored
This is whether or not this ByteStream is in an errored state.
Definition: bytestream.hpp:259
const bool isLive() const
This returns whether or not the stream is connected to "live" data, such as a socket.
Definition: bytestream.hpp:128
bool readByte(char &byte)
This reads a byte from the ByteStream.
int compareWith(const char *buffer, unsigned int bufferLength) const
This compares the ByteStream to the given character buffer and returns the equivalent of "memcmp"...
void copyFrom(const std::string &bytes, Access access)
This copies the bytes from the given string into the ByteStream's character buffer.
std::list< unsigned int > boundaries
This is the list of the boundaries (if applicable) for this stream.
Definition: bytestream.hpp:291
std::chrono::milliseconds _readTimeout
This is the timeout for reads.
Definition: bytestream.hpp:294
bool writeBytes(const char *buffer, unsigned int bufferSize, unsigned int &bytesWritten)
This writes the bytes given to the ByteStream.
Only read operations may be performed.
Definition: bytestream.hpp:38
Both read and write operations may be performed.
Definition: bytestream.hpp:40
Access
This defines the kind of access that a ByteStream will have.
Definition: bytestream.hpp:36
std::condition_variable liveConditionVariable
TODO: DOCUMENT THIS VARIABLE.
Definition: bytestream.hpp:273
std::chrono::milliseconds readTimeout() const
This returns the current read timeout for the stream.
Definition: bytestream.hpp:141
std::mutex liveLock
This is the mutex for handling streaming operations.
Definition: bytestream.hpp:271
void setLive(bool isLive)
This sets the "live" state of the stream.
unsigned int bytesSize
This is the current size of "bytes".
Definition: bytestream.hpp:281
unsigned int remainingReadLength() const
This returns the number of bytes remaining in the stream.
unsigned int remainingWriteLength() const
This returns the number of bytes remaining in the stream.
unsigned int readIndex
This is the current position for reading.
Definition: bytestream.hpp:283
bool nextPacket()
This advances the ByteStream to the next packet, if there is one.
void endPacket()
This ends the current packet and starts a new one.
const bool isErrored() const
This returns whether or not the stream is in an errored state.
Definition: bytestream.hpp:113
unsigned int remainingWriteLength_nolock() const
This returns the number of bytes remaining in the stream.
std::string debugString()
This returns a string that can be printed in order to see debugging information about the ByteStream...
unsigned int writeIndex
This is the current position for writing.
Definition: bytestream.hpp:285
void reset()
This resets the internal character buffer (if owned by the ByteStream).
bool ownBytes
This is whether or not this ByteStream owns the memory pointed to by "bytes".
Definition: bytestream.hpp:277
const bool lastReadTimedOut() const
If the last "read*" function failed, then this will return whether or not the cause was a timeout...
Definition: bytestream.hpp:120
bool readBytes(char *buffer, unsigned int bufferSize, unsigned int &bytesRead)
This reads an arbitrary amount of bytes into the specified character buffer.
void linkFrom(char *bytes, unsigned int bytesSize, Access access)
This links the bytes given to the ByteStream's character buffer.
bool hasNextPacket()
This returns whether or not there is a next packet.
unsigned int remainingReadLength_nolock() const
This returns the number of bytes remaining in the stream.
bool _lastReadTimedOut
If this is a live stream, then this will be set to true if the last "read*" function failed due to a ...
Definition: bytestream.hpp:263
void freeBytes()
This frees the memory associated with the internal character buffer.
void copyTo(std::vector< char > &buffer) const
This copies the portion of the ByteStream that's currently available for reading to the specified tar...
char * bytes
This is the buffer allocated for this ByteStream.
Definition: bytestream.hpp:279
bool grow(unsigned int increment)
This attempts to increase the size of the buffer by the specified amount.
bool waitForReading(unsigned int increment)
This attempts to wait for the given number of bytes to become available for reading.
bool _isLive
This is whether or not this ByteStream is hooked up (in some way) to live data.
Definition: bytestream.hpp:269