ByteQueue Class Reference

Data structure used to store byte strings. More...

`#include <queue.h>`

Inheritance diagram for ByteQueue:

## Classes

class | Walker
| A ByteQueue iterator. More...

## Public Member Functions

| ByteQueue (size_t nodeSize=0)
| Construct a ByteQueue.
| ByteQueue (const ByteQueue &copy)
| Copy construct a ByteQueue.
lword | MaxRetrievable () const
| Provides the number of bytes ready for retrieval.
bool | AnyRetrievable () const
| Determines whether bytes are ready for retrieval.
void | IsolatedInitialize (const NameValuePairs &parameters)
| Initialize or reinitialize this object, without signal propagation.
byte * | CreatePutSpace (size_t &size)
| Request space which can be written into by the caller.
size_t | Put2 (const byte *inString, size_t length, int messageEnd, bool blocking)
| Input multiple bytes for processing.
size_t | Get (byte &outByte)
| Retrieve a 8-bit byte.
size_t | Get (byte *outString, size_t getMax)
| Retrieve a block of bytes.
size_t | Peek (byte &outByte) const
| Peek a 8-bit byte.
size_t | Peek (byte *outString, size_t peekMax) const
| Peek a block of bytes.
size_t | TransferTo2 (BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
| Transfer bytes from this object to another BufferedTransformation.
size_t | CopyRangeTo2 (BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const
| Copy bytes from this object to another BufferedTransformation.
void | SetNodeSize (size_t nodeSize)
| Set node size.
lword | CurrentSize () const
| Determine data size.
bool | IsEmpty () const
| Determine data availability.
void | Clear ()
| Empty the queue.
void | Unget (byte inByte)
| Insert data in the queue.
void | Unget (const byte *inString, size_t length)
| Insert data in the queue.
const byte * | Spy (size_t &contiguousSize) const
| Peek data in the queue.
void | LazyPut (const byte *inString, size_t size)
| Insert data in the queue.
void | LazyPutModifiable (byte *inString, size_t size)
| Insert data in the queue.
void | UndoLazyPut (size_t size)
| Remove data from the queue.
void | FinalizeLazyPut ()
| Insert data in the queue.
ByteQueue & | operator= (const ByteQueue &rhs)
| Assign contents from another ByteQueue.
bool | operator== (const ByteQueue &rhs) const
| Bitwise compare two ByteQueue.
bool | operator!= (const ByteQueue &rhs) const
| Bitwise compare two ByteQueue.
byte | operator[] (lword index) const
| Retrieve data from the queue.
void | swap (ByteQueue &rhs)
| Swap contents with another ByteQueue.
Public Member Functions inherited from Bufferless< BufferedTransformation >
bool | IsolatedFlush (bool hardFlush, bool blocking)
| Flushes data buffered by this object, without signal propagation.
Public Member Functions inherited from BufferedTransformation
| BufferedTransformation ()
| Construct a BufferedTransformation.
BufferedTransformation & | Ref ()
| Provides a reference to this object.
virtual bool | Attachable ()
| Determines whether the object allows attachment.
virtual BufferedTransformation * | AttachedTransformation ()
| Returns the object immediately attached to this object.
virtual const BufferedTransformation * | AttachedTransformation () const
| Returns the object immediately attached to this object.
virtual void | Detach (BufferedTransformation *newAttachment=NULL)
| Delete the current attachment chain and attach a new one.
virtual void | Attach (BufferedTransformation *newAttachment)
| Add newAttachment to the end of attachment chain.
size_t | Put (byte inByte, bool blocking=true)
| Input a byte for processing.
size_t | Put (const byte *inString, size_t length, bool blocking=true)
| Input a byte buffer for processing.
size_t | PutWord16 (word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 16-bit word for processing.
size_t | PutWord32 (word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 32-bit word for processing.
size_t | PutWord64 (word64 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 64-bit word for processing.
virtual bool | CanModifyInput () const
| Determines whether input can be modified by the callee.
size_t | PutModifiable (byte *inString, size_t length, bool blocking=true)
| Input multiple bytes that may be modified by callee.
bool | MessageEnd (int propagation=-1, bool blocking=true)
| Signals the end of messages to the object.
size_t | PutMessageEnd (const byte *inString, size_t length, int propagation=-1, bool blocking=true)
| Input multiple bytes for processing and signal the end of a message.
virtual size_t | PutModifiable2 (byte *inString, size_t length, int messageEnd, bool blocking)
| Input multiple bytes that may be modified by callee.
unsigned int | GetMaxWaitObjectCount () const
| Retrieves the maximum number of waitable objects.
void | GetWaitObjects (WaitObjectContainer &container, CallStack const &callStack)
| Retrieves waitable objects.
virtual bool | IsolatedMessageSeriesEnd (bool blocking)
| Marks the end of a series of messages, without signal propagation.
virtual void | Initialize (const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1)
| Initialize or reinitialize this object, with signal propagation.
virtual bool | Flush (bool hardFlush, int propagation=-1, bool blocking=true)
| Flush buffered input and/or output, with signal propagation.
virtual bool | MessageSeriesEnd (int propagation=-1, bool blocking=true)
| Marks the end of a series of messages, with signal propagation.
virtual void | SetAutoSignalPropagation (int propagation)
| Set propagation of automatically generated and transferred signals.
virtual int | GetAutoSignalPropagation () const
| Retrieve automatic signal propagation value.
size_t | GetWord16 (word16 &value, ByteOrder order=BIG_ENDIAN_ORDER)
| Retrieve a 16-bit word.
size_t | GetWord32 (word32 &value, ByteOrder order=BIG_ENDIAN_ORDER)
| Retrieve a 32-bit word.
size_t | GetWord64 (word64 &value, ByteOrder order=BIG_ENDIAN_ORDER)
| Retrieve a 64-bit word.
size_t | PeekWord16 (word16 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
| Peek a 16-bit word.
size_t | PeekWord32 (word32 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
| Peek a 32-bit word.
size_t | PeekWord64 (word64 &value, ByteOrder order=BIG_ENDIAN_ORDER) const
| Peek a 64-bit word.
lword | TransferTo (BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL)
| move transferMax bytes of the buffered output to target as input
virtual lword | Skip (lword skipMax=LWORD_MAX)
| Discard skipMax bytes from the output buffer.
lword | CopyTo (BufferedTransformation &target, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const
| Copy bytes from this object to another BufferedTransformation.
lword | CopyRangeTo (BufferedTransformation &target, lword position, lword copyMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL) const
| Copy bytes from this object using an index to another BufferedTransformation.
virtual lword | TotalBytesRetrievable () const
| Provides the number of bytes ready for retrieval.
virtual unsigned int | NumberOfMessages () const
| Provides the number of meesages processed by this object.
virtual bool | AnyMessages () const
| Determines if any messages are available for retrieval.
virtual bool | GetNextMessage ()
| Start retrieving the next message.
virtual unsigned int | SkipMessages (unsigned int count=UINT_MAX)
| Skip a number of meessages.
unsigned int | TransferMessagesTo (BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL)
| Transfer messages from this object to another BufferedTransformation.
unsigned int | CopyMessagesTo (BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const
| Copy messages from this object to another BufferedTransformation.
virtual void | SkipAll ()
| Skip all messages in the series.
void | TransferAllTo (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL)
| Transfer all bytes from this object to another BufferedTransformation.
void | CopyAllTo (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL) const
| Copy messages from this object to another BufferedTransformation.
virtual bool | GetNextMessageSeries ()
| Retrieve the next message in a series.
virtual unsigned int | NumberOfMessagesInThisSeries () const
| Provides the number of messages in a series.
virtual unsigned int | NumberOfMessageSeries () const
| Provides the number of messages in a series.
size_t | TransferMessagesTo2 (BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
| Transfer messages from this object to another BufferedTransformation.
size_t | TransferAllTo2 (BufferedTransformation &target, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true)
| Transfer all bytes from this object to another BufferedTransformation.
size_t | ChannelPut (const std::string &channel, byte inByte, bool blocking=true)
| Input a byte for processing on a channel.
size_t | ChannelPut (const std::string &channel, const byte *inString, size_t length, bool blocking=true)
| Input a byte buffer for processing on a channel.
size_t | ChannelPutModifiable (const std::string &channel, byte *inString, size_t length, bool blocking=true)
| Input multiple bytes that may be modified by callee on a channel.
size_t | ChannelPutWord16 (const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 16-bit word for processing on a channel.
size_t | ChannelPutWord32 (const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 32-bit word for processing on a channel.
size_t | ChannelPutWord64 (const std::string &channel, word64 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true)
| Input a 64-bit word for processing on a channel.
bool | ChannelMessageEnd (const std::string &channel, int propagation=-1, bool blocking=true)
| Signal the end of a message.
size_t | ChannelPutMessageEnd (const std::string &channel, const byte *inString, size_t length, int propagation=-1, bool blocking=true)
| Input multiple bytes for processing and signal the end of a message.
virtual byte * | ChannelCreatePutSpace (const std::string &channel, size_t &size)
| Request space which can be written into by the caller.
virtual size_t | ChannelPut2 (const std::string &channel, const byte *inString, size_t length, int messageEnd, bool blocking)
| Input multiple bytes for processing on a channel.
virtual size_t | ChannelPutModifiable2 (const std::string &channel, byte *inString, size_t length, int messageEnd, bool blocking)
| Input multiple bytes that may be modified by callee on a channel.
virtual bool | ChannelFlush (const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true)
| Flush buffered input and/or output on a channel.
virtual bool | ChannelMessageSeriesEnd (const std::string &channel, int propagation=-1, bool blocking=true)
| Marks the end of a series of messages on a channel.
virtual void | SetRetrievalChannel (const std::string &channel)
| Sets the default retrieval channel.
Public Member Functions inherited from Algorithm
| Algorithm (bool checkSelfTestStatus=true)
| Interface for all crypto algorithms.
virtual std::string | AlgorithmName () const
| Provides the name of this algorithm.
virtual std::string | AlgorithmProvider () const
| Retrieve the provider of this algorithm.
Public Member Functions inherited from Clonable
virtual Clonable * | Clone () const
| Copies this object.
Public Member Functions inherited from Waitable
bool | Wait (unsigned long milliseconds, CallStack const &callStack)
| Wait on this object.

## Friends

class | Walker

## Detailed Description

Data structure used to store byte strings.

The queue is implemented as a linked list of byte arrays. Each byte array is stored in a ByteQueueNode.

See also
  ByteQueue on the Crypto++ wiki.

Since
  Crypto++ 2.0

Definition at line 22 of file queue.h.

## Constructor & Destructor Documentation

## ByteQueue() [1/2]

ByteQueue::ByteQueue | ( | size_t | nodeSize = 0 | ) |

Construct a ByteQueue.

Parameters

  nodeSize | the initial node size

Internally, ByteQueue uses a ByteQueueNode to store bytes, and nodeSize determines the size of the ByteQueueNode. A value of 0 indicates the ByteQueueNode should be automatically sized, which means a value of 256 is used.

## ByteQueue() [2/2]

ByteQueue::ByteQueue | ( | const ByteQueue & | copy | ) |

Copy construct a ByteQueue.

Parameters

  copy | the other ByteQueue

## Member Function Documentation

## MaxRetrievable()

lword ByteQueue::MaxRetrievable | ( |  | ) | const

inline virtual

Provides the number of bytes ready for retrieval.

Returns
  the number of bytes ready for retrieval

The number of bytes available are dependent on the source. If an exact value is available, then the exact value is returned. The exact value can include 0 if the source is exhausted.

Some stream-based sources do not allow seeking() on the underlying stream, such as some FileSource(). If the stream does not allow seeking() then MaxRetrievable() returns LWORD_MAX to indicate there are still bytes to be retrieved.

Reimplemented from BufferedTransformation.

Definition at line 40 of file queue.h.

## AnyRetrievable()

bool ByteQueue::AnyRetrievable | ( |  | ) | const

inline virtual

Determines whether bytes are ready for retrieval.

Returns
  true if bytes are available for retrieval, false otherwise

Reimplemented from BufferedTransformation.

Definition at line 42 of file queue.h.

## IsolatedInitialize()

void ByteQueue::IsolatedInitialize | ( | const NameValuePairs & | parameters | ) |

virtual

Initialize or reinitialize this object, without signal propagation.

Parameters

  parameters | a set of NameValuePairs to initialize this object

Exceptions

  NotImplemented |

IsolatedInitialize() is used to initialize or reinitialize an object using a variable number of arbitrarily typed arguments. The function avoids the need for multiple constructors providing all possible combintations of configurable parameters.

IsolatedInitialize() does not call Initialize() on attached transformations. If initialization should be propagated, then use the Initialize() function.

If a derived class does not override IsolatedInitialize(), then the base class throws NotImplemented.

Reimplemented from BufferedTransformation.

## CreatePutSpace()

byte * ByteQueue::CreatePutSpace | ( | size_t & | size | ) |

virtual

Request space which can be written into by the caller.

Parameters

  size | the requested size of the buffer

Returns
  byte pointer to the space to input data

The purpose of this method is to help avoid extra memory allocations.

size is an IN and OUT parameter and used as a hint. When the call is made, size is the requested size of the buffer. When the call returns, size is the size of the array returned to the caller.

The base class implementation sets size to 0 and returns NULL.

Note
  Some objects, like ArraySink, cannot create a space because its fixed. In the case of an ArraySink, the pointer to the array is returned and the size is remaining size.

Reimplemented from BufferedTransformation.

## Put2()

size_t ByteQueue::Put2 | ( | const byte * | inString,
|  | size_t | length,
|  | int | messageEnd,
|  | bool | blocking )

virtual

Input multiple bytes for processing.

Parameters

  inString | the byte buffer to process
  length | the size of the string, in bytes
  messageEnd | means how many filters to signal MessageEnd() to, including this one
  blocking | specifies whether the object should block when processing input

Returns
  the number of bytes that remain to be processed (i.e., bytes not processed). 0 indicates all bytes were processed.

Derived classes must implement Put2().

Implements BufferedTransformation.

## Get() [1/2]

size_t ByteQueue::Get | ( | byte & | outByte | ) |

virtual

Retrieve a 8-bit byte.

Parameters

  outByte | the 8-bit value to be retrieved

Returns
  the number of bytes consumed during the call.

Use the return value of Get to detect short reads.

Reimplemented from BufferedTransformation.

## Get() [2/2]

size_t ByteQueue::Get | ( | byte * | outString,
|  | size_t | getMax )

virtual

Retrieve a block of bytes.

Parameters

  outString | a block of bytes
  getMax | the number of bytes to Get

Returns
  the number of bytes consumed during the call.

Use the return value of Get to detect short reads.

Reimplemented from BufferedTransformation.

## Peek() [1/2]

size_t ByteQueue::Peek | ( | byte & | outByte | ) | const

virtual

Peek a 8-bit byte.

Parameters

  outByte | the 8-bit value to be retrieved

Returns
  the number of bytes read during the call.

Peek does not remove bytes from the object. Use the return value of Get() to detect short reads.

Reimplemented from BufferedTransformation.

## Peek() [2/2]

size_t ByteQueue::Peek | ( | byte * | outString,
|  | size_t | peekMax ) const

virtual

Peek a block of bytes.

Parameters

  outString | a block of bytes
  peekMax | the number of bytes to Peek

Returns
  the number of bytes read during the call.

Peek does not remove bytes from the object. Use the return value of Peek() to detect short reads.

Reimplemented from BufferedTransformation.

## TransferTo2()

size_t ByteQueue::TransferTo2 | ( | BufferedTransformation & | target,
|  | lword & | byteCount,
|  | const std::string & | channel = DEFAULT_CHANNEL,
|  | bool | blocking = true )

virtual

Transfer bytes from this object to another BufferedTransformation.

Parameters

  target | the destination BufferedTransformation
  byteCount | the number of bytes to transfer
  channel | the channel on which the transfer should occur
  blocking | specifies whether the object should block when processing input

Returns
  the number of bytes that remain in the transfer block (i.e., bytes not transferred)

TransferTo2() removes bytes from this object and moves them to the destination. Transfer begins at the index position in the current stream, and not from an absolute position in the stream.

byteCount is an IN and OUT parameter. When the call is made, byteCount is the requested size of the transfer. When the call returns, byteCount is the number of bytes that were transferred.

Implements BufferedTransformation.

## CopyRangeTo2()

size_t ByteQueue::CopyRangeTo2 | ( | BufferedTransformation & | target,
|  | lword & | begin,
|  | lword | end = LWORD_MAX,
|  | const std::string & | channel = DEFAULT_CHANNEL,
|  | bool | blocking = true ) const

virtual

Copy bytes from this object to another BufferedTransformation.

Parameters

  target | the destination BufferedTransformation
  begin | the 0-based index of the first byte to copy in the stream
  end | the 0-based index of the last byte to copy in the stream
  channel | the channel on which the transfer should occur
  blocking | specifies whether the object should block when processing input

Returns
  the number of bytes that remain in the copy block (i.e., bytes not copied)

CopyRangeTo2 copies bytes from this object to the destination. The bytes are not removed from this object. Copying begins at the index position in the current stream, and not from an absolute position in the stream.

begin is an IN and OUT parameter. When the call is made, begin is the starting position of the copy. When the call returns, begin is the position of the first byte that was not copied (which may be different than end). begin can be used for subsequent calls to CopyRangeTo2().

Implements BufferedTransformation.

## SetNodeSize()

void ByteQueue::SetNodeSize | ( | size_t | nodeSize | ) |

Set node size.

Parameters

  nodeSize | the new node size, in bytes

The default node size is 256.

## CurrentSize()

lword ByteQueue::CurrentSize | ( |  | ) | const

Determine data size.

Returns
  the data size, in bytes

## IsEmpty()

bool ByteQueue::IsEmpty | ( |  | ) | const

Determine data availability.

Returns
  true if the ByteQueue has data, false otherwise

## Unget() [1/2]

void ByteQueue::Unget | ( | byte | inByte | ) |

Insert data in the queue.

Parameters

  inByte | a byte to insert

Unget() inserts a byte at the head of the queue

## Unget() [2/2]

void ByteQueue::Unget | ( | const byte * | inString,
|  | size_t | length )

Insert data in the queue.

Parameters

  inString | a byte array to insert
  length | the size of the byte array

Unget() inserts a byte array at the head of the queue

## Spy()

const byte * ByteQueue::Spy | ( | size_t & | contiguousSize | ) | const

Peek data in the queue.

Parameters

  contiguousSize | the size of the data

Spy() peeks at data at the head of the queue. Spy() does not remove data from the queue.

The data's size is returned in contiguousSize. Spy() returns the size of the first byte array in the list. The entire data may be larger since the queue is a linked list of byte arrays.

## LazyPut()

void ByteQueue::LazyPut | ( | const byte * | inString,
|  | size_t | size )

Insert data in the queue.

Parameters

  inString | a byte array to insert
  size | the length of the byte array

LazyPut() inserts a byte array at the tail of the queue. The data may not be copied at this point. Rather, the pointer and size to external data are recorded.

Another call to Put() or LazyPut() will force the data to be copied. When lazy puts are used, the data is copied when FinalizeLazyPut() is called.

See also
  LazyPutter

## LazyPutModifiable()

void ByteQueue::LazyPutModifiable | ( | byte * | inString,
|  | size_t | size )

Insert data in the queue.

Parameters

  inString | a byte array to insert
  size | the length of the byte array

LazyPut() inserts a byte array at the tail of the queue. The data may not be copied at this point. Rather, the pointer and size to external data are recorded.

Another call to Put() or LazyPut() will force the data to be copied. When lazy puts are used, the data is copied when FinalizeLazyPut() is called.

See also
  LazyPutter

## UndoLazyPut()

void ByteQueue::UndoLazyPut | ( | size_t | size | ) |

Remove data from the queue.

Parameters

  size | the length of the data

Exceptions

  InvalidArgument | if there is no lazy data in the queue or if size is larger than the lazy string

UndoLazyPut() truncates data inserted using LazyPut() by modifying size.

See also
  LazyPutter

## FinalizeLazyPut()

void ByteQueue::FinalizeLazyPut | ( |  | ) |

Insert data in the queue.

FinalizeLazyPut() copies external data inserted using LazyPut() or LazyPutModifiable() into the tail of the queue.

See also
  LazyPutter

## operator=()

ByteQueue & ByteQueue::operator= | ( | const ByteQueue & | rhs | ) |

Assign contents from another ByteQueue.

Parameters

  rhs | the other ByteQueue

Returns
  reference to this ByteQueue

## operator==()

bool ByteQueue::operator== | ( | const ByteQueue & | rhs | ) | const

Bitwise compare two ByteQueue.

Parameters

  rhs | the other ByteQueue

Returns
  true if the size and bits are equal, false otherwise

operator==() walks each ByteQueue comparing bytes in each queue. operator==() is not constant time.

## operator!=()

bool ByteQueue::operator!= | ( | const ByteQueue & | rhs | ) | const

inline

Bitwise compare two ByteQueue.

Parameters

  rhs | the other ByteQueue

Returns
  true if the size and bits are not equal, false otherwise

operator!=() is implemented in terms of operator==(). operator==() is not constant time.

Definition at line 151 of file queue.h.

## operator[]()

byte ByteQueue::operator[] | ( | lword | index | ) | const

Retrieve data from the queue.

Parameters

  index | of byte to retrieve

Returns
  byte at the specified index

operator[]() does not perform bounds checking.

## swap()

void ByteQueue::swap | ( | ByteQueue & | rhs | ) |

Swap contents with another ByteQueue.

Parameters

  rhs | the other ByteQueue

## Friends And Related Symbol Documentation

## Walker

friend class Walker

friend

Definition at line 198 of file queue.h.

The documentation for this class was generated from the following file:

- queue.h