Tag Class Reference

Tag class represents one Tag in the protocol. More...

#include <tag.h>

List of all members.


Public Member Functions

 Tag (std::istream &i)
 Construct and load from input stream.
std::string dump (bool data=true) const
 Generate a debugging string from this tag's contents.
Construct using opcode (or name) and value. Only string and
integer data types are allowed for construction.

 Tag (uint8_t opcode, const std::string &value)
 Tag (uint8_t opcode, uint32_t value)
 Tag (const std::string &name, const std::string &value)
 Tag (const std::string &name, uint32_t value)
Accessors for preconstructed or preloaded Tag data.
uint32_t getInt () const
float getFloat () const
std::string getStr () const
uint8_t getOpcode () const
std::string getName () const
uint8_t getValueType () const

Private Types

enum  ValueTypes {
  TT_HASH = 0x01, TT_STRING = 0x02, TT_UINT32 = 0x03, TT_FLOAT = 0x04,
  TT_BOOL = 0x05, TT_BOOLARR = 0x06, TT_BLOB = 0x07, TT_UINT16 = 0x08,
  TT_UINT8 = 0x09, TT_BSOB = 0x0a
}
 Different tag value types used in the protocol. More...

Private Member Functions

 Tag ()
 Default constructor protected.

Private Attributes

uint8_t m_opcode
 Opcode.
std::string m_name
 Name (in case of string-tag).
boost::any m_value
 Value.
uint8_t m_valueType
 Type of value, one of ValueTypes.

Friends

std::ostream & operator<< (std::ostream &o, const Tag &t)
 Writes ed2k-compatible tag structure to specified output stream.
void warnUnHandled (const std::string &loc, const Tag &t)
 Small helper function to localize the warning messages on unhandled tags found while parsing.

Detailed Description

Tag class represents one Tag in the protocol.

A tag has its identifier (either 8-bit opcode or string value), and a data field. Refer to eDonkey2000 protocol tag system overview for detailed information on the Tag parsing system.

Definition at line 44 of file tag.h.


Member Enumeration Documentation

enum Tag::ValueTypes [private]
 

Different tag value types used in the protocol.

Enumeration values:
TT_HASH  unsupported, 16 bytes
TT_STRING  [u16]len[len]data
TT_UINT32  4 bytes
TT_FLOAT  4 bytes
TT_BOOL  unsupported, 1 byte
TT_BOOLARR  unsupported, [u16]len[len]data
TT_BLOB  unsupported, [u16]len[len]data
TT_UINT16  2 bytes
TT_UINT8  1 byte
TT_BSOB  unsupported, [u16]len[len]data

Definition at line 124 of file tag.h.


Constructor & Destructor Documentation

Tag::Tag std::istream &  i  ) 
 

Construct and load from input stream.

Parameters:
i Input stream to read the data from
Exceptions:
TagError if parsing fails

Definition at line 27 of file tag.cpp.

References dump(), m_name, m_opcode, m_value, m_valueType, TRACE_TAG(), TT_BLOB, TT_BOOL, TT_BOOLARR, TT_FLOAT, TT_HASH, TT_STRING, TT_UINT16, TT_UINT32, and TT_UINT8.

Tag::Tag uint8_t  opcode,
const std::string &  value
[inline]
 

Definition at line 59 of file tag.h.

References m_opcode, m_value, m_valueType, and TT_STRING.

Tag::Tag uint8_t  opcode,
uint32_t  value
[inline]
 

Definition at line 61 of file tag.h.

References m_opcode, m_value, m_valueType, and TT_UINT32.

Tag::Tag const std::string &  name,
const std::string &  value
[inline]
 

Definition at line 63 of file tag.h.

References m_name, m_opcode, m_value, m_valueType, and TT_STRING.

Tag::Tag const std::string &  name,
uint32_t  value
[inline]
 

Definition at line 65 of file tag.h.

References m_name, m_opcode, m_value, m_valueType, and TT_UINT32.

Tag::Tag  )  [private]
 

Default constructor protected.


Member Function Documentation

uint32_t Tag::getInt  )  const [inline]
 

Definition at line 73 of file tag.h.

References m_value.

Referenced by dump(), ED2KPacket::Hello::load(), ED2KPacket::MuleInfo::MuleInfo(), ED2KPacket::SearchResult::SearchResult(), and Detail::Server::Server().

float Tag::getFloat  )  const [inline]
 

Definition at line 83 of file tag.h.

References m_value.

Referenced by dump().

std::string Tag::getStr  )  const [inline]
 

Definition at line 93 of file tag.h.

References m_value.

Referenced by dump(), ED2KPacket::Hello::load(), ED2KPacket::MuleInfo::MuleInfo(), ED2KPacket::SearchResult::SearchResult(), Detail::Server::Server(), and ED2KPacket::ServerIdent::ServerIdent().

uint8_t Tag::getOpcode  )  const [inline]
 

Definition at line 103 of file tag.h.

References m_opcode.

Referenced by ED2KPacket::Hello::load(), ED2KPacket::MuleInfo::MuleInfo(), ED2KPacket::SearchResult::SearchResult(), Detail::Server::Server(), and ED2KPacket::ServerIdent::ServerIdent().

std::string Tag::getName  )  const [inline]
 

Definition at line 104 of file tag.h.

References m_name.

Referenced by Detail::Server::Server().

uint8_t Tag::getValueType  )  const [inline]
 

Definition at line 105 of file tag.h.

References m_valueType.

std::string Tag::dump bool  data = true  )  const
 

Generate a debugging string from this tag's contents.

Parameters:
data If true, also include tag data/value field
Returns:
Human-readable (mostly) hexdump of tag's contents

Definition at line 149 of file tag.cpp.

References getFloat(), getInt(), getStr(), m_name, m_opcode, m_valueType, TT_FLOAT, TT_STRING, TT_UINT16, TT_UINT32, and TT_UINT8.

Referenced by ED2KPacket::Hello::load(), and Tag().


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  o,
const Tag t
[friend]
 

Writes ed2k-compatible tag structure to specified output stream.

Definition at line 104 of file tag.cpp.

void warnUnHandled const std::string &  loc,
const Tag t
[friend]
 

Small helper function to localize the warning messages on unhandled tags found while parsing.

Parameters:
loc Location where the tag was found, e.g. "server.met"
t The unhandled tag itself.

Definition at line 177 of file tag.cpp.


Member Data Documentation

uint8_t Tag::m_opcode [private]
 

Opcode.

Definition at line 118 of file tag.h.

Referenced by dump(), getOpcode(), and Tag().

std::string Tag::m_name [private]
 

Name (in case of string-tag).

Definition at line 119 of file tag.h.

Referenced by dump(), getName(), and Tag().

boost::any Tag::m_value [private]
 

Value.

Definition at line 120 of file tag.h.

Referenced by getFloat(), getInt(), getStr(), and Tag().

uint8_t Tag::m_valueType [private]
 

Type of value, one of ValueTypes.

Definition at line 121 of file tag.h.

Referenced by dump(), getValueType(), and Tag().


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