42 #ifndef _DWMIPV4UDPPAYLOAD_HH_ 43 #define _DWMIPV4UDPPAYLOAD_HH_ 100 std::pair<uint16_t,const uint8_t *> Payload()
const;
111 uint32_t
Sum()
const;
118 template <
typename T>
122 if (_payload.first) {
123 std::istringstream is(std::string((
const char *)_payload.second,
135 template <
typename T>
141 uint16_t maxPayloadLen = 65535 - (20 + 8);
143 if (payloadLen <= maxPayloadLen) {
144 std::ostringstream os;
146 _payload.first = payloadLen;
147 _payload.second = (uint8_t *)calloc(1, _payload.first);
148 assert(_payload.second);
149 memcpy(_payload.second, os.str().c_str(), _payload.first);
164 std::istream &
Read(std::istream & is, uint16_t len);
169 std::ostream &
Write(std::ostream & os)
const;
175 ssize_t
Read(
int fd, uint16_t len);
181 ssize_t
Write(
int fd)
const;
187 size_t Read(FILE *f, uint16_t len);
193 size_t Write(FILE *f)
const;
199 int Read(gzFile gzf, uint16_t len);
205 int Write(gzFile gzf)
const;
211 int BZRead(BZFILE *bzf, uint16_t len);
217 int BZWrite(BZFILE *bzf)
const;
226 std::pair<uint16_t, uint8_t *> _payload;
230 void Allocate(uint16_t len);
235 #endif // _DWMIPV4UDPPAYLOAD_HH_ This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmGZWritable.hh:57
std::string ToString() const
Returns the payload as a string.
uint32_t Sum() const
Returns the IP sum of the payload, which can be used as part of UDP checksum computation.
int BZWrite(BZFILE *bzf) const
Writes the payload to the given BZFILE bzf.
std::ostream & Write(std::ostream &os) const
Writes the payload to the given ostream os.
void Clear()
Clears the payload.
std::istream & Read(std::istream &is, uint16_t len)
Reads len bytes of the payload from the given istream is.
~Ipv4UdpPayload()
Destructor.
bool GetPayload(T &payload) const
Copies the payload into payload.
Definition: DwmIpv4UdpPayload.hh:119
Encapsulates a UDP payload.
Definition: DwmIpv4UdpPayload.hh:64
static std::ostream & Write(std::ostream &os, char c)
Writes c to os. Returns os.
Ipv4UdpPayload()
Constructor.
static std::istream & Read(std::istream &is, char &c)
Reads c from is. Returns is.
Definition: DwmBZ2IO.hh:67
Dwm::IO class definition.
uint32_t StreamedLength() const
Returns the number of bytes that would be written if one of the Write() members were called...
This class defines an interface for classes that can write their contents to an ostream, file descriptor or FILE pointer.
Definition: DwmWritable.hh:58
static uint32_t StreamedLength(char c)
Returns the number of bytes that would be written if we called Write() for a char.
Definition: DwmIO.hh:92
This class is a pure virtual class, defining an interface for classes that can write their contents t...
Definition: DwmBZ2Writable.hh:57
int BZRead(BZFILE *bzf, uint16_t len)
Reads len bytes of the payload from the given BZFILE bzf.
bool SetPayload(const T &payload)
Sets the payload to payload.
Definition: DwmIpv4UdpPayload.hh:136