Protocols::Gnutella::Packets::BinaryWriter Class Reference

#include <BinaryWriter.h> [code]

Inherits Utils::Encodings::BinaryWriter.

Inheritance diagram for Protocols::Gnutella::Packets::BinaryWriter:

Inheritance graph
[legend]
Collaboration diagram for Protocols::Gnutella::Packets::BinaryWriter:

Collaboration graph
[legend]
List of all members.

Detailed Description

Helper to write Gnutella packet fields form a raw buffer (QByteArray).

Extends the base class Utils::Encodings::BinaryReader to provide utility functions for reading and writing Gnutella packets. The default byte order is little endian. Extends the interface of the base class by providing helpers that write Gnutella specific packet fields.

Definition at line 39 of file BinaryWriter.h.

Public Member Functions

 BinaryWriter (bool autoGrow=true)
 Constructs a BinaryWriter object to write in an internal growable buffer.
 BinaryWriter (QByteArray *buffer, bool autoGrow=false)
 Constructs a BinaryWriter object to write in buffer.
void writeUuid (const QUuid &)
 Write a 16 byte UUID.
void writeIPv4Address (const QHostAddress &)
 Writes the four bytes of an IPv4 address in big-endian.
void writeGgepBlock (const GgepBlock &)
 Write a GgepBlock that contains Ggeps.
void writeMinSpeed (const MinSpeed &speed)
 Write the MinSpeed flags for QueryPacket.
void writeVendorCode (const VendorCode &code)
 Write a VendorCode object.
void writeQueryData (const QueryData &)
 Write a QueryData which is essentially a HUGE GEM extension block.
void writeQueryHitsResultSet (const ResultSet &resultSet)
 Writes a ResultSet object.
void writeQueryHitsData (const QueryHitsData &hitsData)
 Writes a QueryHitsData object.

Private Member Functions

void writeGgepBlockExtensionHeader (const Ggep *extension, const Ggep *lastExtension)
 Helper to write a GGEP extension header (flags and ID).
void writeGgepBlockDataLength (int length)
 Helper to write a GGEP extension's data length.
void writeHugeGemBlock (const HugeGemBlock &block)
 Helper to write a HUGE GEM extension block.


Constructor & Destructor Documentation

BinaryWriter::BinaryWriter bool  autoGrow = true  ) 
 

Constructs a BinaryWriter object to write in an internal growable buffer.

Definition at line 34 of file BinaryWriter.cpp.

BinaryWriter::BinaryWriter QByteArray *  buffer,
bool  autoGrow = false
 

Constructs a BinaryWriter object to write in buffer.

Definition at line 28 of file BinaryWriter.cpp.


Member Function Documentation

void BinaryWriter::writeGgepBlock const GgepBlock block  ) 
 

Write a GgepBlock that contains Ggeps.

Parameters:
block is the GgepBlock to write to the BinaryWriter.
An empty GGEP block results in no data written to the underlying buffer. If block is non-empty, the GgepBlock::MagicByte marker is written first followed by all contained Ggep extensions, properly formatted.

Definition at line 87 of file BinaryWriter.cpp.

void BinaryWriter::writeGgepBlockDataLength int  length  )  [private]
 

Helper to write a GGEP extension's data length.

Parameters:
length is the number to encode and write in GGEP's data length format.

Definition at line 130 of file BinaryWriter.cpp.

void BinaryWriter::writeGgepBlockExtensionHeader const Ggep extension,
const Ggep lastExtension
[private]
 

Helper to write a GGEP extension header (flags and ID).

Parameters:
extension is the Ggep object for which to write the header.

Definition at line 109 of file BinaryWriter.cpp.

void BinaryWriter::writeHugeGemBlock const HugeGemBlock block  )  [private]
 

Helper to write a HUGE GEM extension block.

Parameters:
block is the HugeGemBlock to write.
Each of the extensions block is written to the BinaryWriter so that they are separated with a 0x1C bytes. Nothing is written if the block is empty.

Definition at line 190 of file BinaryWriter.cpp.

void BinaryWriter::writeIPv4Address const QHostAddress &  address  ) 
 

Writes the four bytes of an IPv4 address in big-endian.

Parameters:
address to write as a four byte big-endian int.
Precondition:
assress must be an IPv4 address.

Definition at line 70 of file BinaryWriter.cpp.

void BinaryWriter::writeMinSpeed const MinSpeed speed  ) 
 

Write the MinSpeed flags for QueryPacket.

Parameters:
speed is the MinSpeed object to write to BinaryReader in the corresponding encoding.

Definition at line 154 of file BinaryWriter.cpp.

void BinaryWriter::writeQueryData const QueryData data  ) 
 

Write a QueryData which is essentially a HUGE GEM extension block.

Parameters:
data is the QueryData to write to BinaryReader.

Definition at line 144 of file BinaryWriter.cpp.

void BinaryWriter::writeQueryHitsData const QueryHitsData hitsData  ) 
 

Writes a QueryHitsData object.

Parameters:
hitsData is the QueryHitsData object to write to the BinaryWriter.

Definition at line 218 of file BinaryWriter.cpp.

void BinaryWriter::writeQueryHitsResultSet const ResultSet resultSet  ) 
 

Writes a ResultSet object.

Parameters:
resultSet is the ResultSet object to write to the BinaryWriter.

Definition at line 264 of file BinaryWriter.cpp.

void BinaryWriter::writeUuid const QUuid &  uuid  ) 
 

Write a 16 byte UUID.

Parameters:
uuid to write to the BinaryWriter.
A UUID is a 16 byte string or can be interpreted as a 128 bit integer. Since QUuid does not provide a conversion to a QByteArray, we need to do the conversion here.

Definition at line 47 of file BinaryWriter.cpp.

void BinaryWriter::writeVendorCode const VendorCode code  ) 
 

Write a VendorCode object.

Parameters:
code is the VendorCode object to write to BinaryWriter.

Definition at line 177 of file BinaryWriter.cpp.


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