CatapultServer  v0.5.0.1 (Elephant)
PacketExtractor.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "IoTypes.h"
23 #include "Packet.h"
24 #include <stddef.h>
25 
26 namespace catapult { namespace ionet {
27 
28 #define PACKET_EXTRACT_RESULT_LIST \
29  /* A packet was succesfully extracted. */ \
30  ENUM_VALUE(Success) \
31  \
32  /* A packet was not extracted due to insufficient data. */ \
33  ENUM_VALUE(Insufficient_Data) \
34  \
35  /* A packet was not extracted due to a packet error. */ \
36  ENUM_VALUE(Packet_Error)
37 
38 #define ENUM_VALUE(LABEL) LABEL,
39  enum class PacketExtractResult {
42  };
43 #undef ENUM_VALUE
44 
46  std::ostream& operator<<(std::ostream& out, PacketExtractResult value);
47 
50  public:
53  PacketExtractor(ByteBuffer& data, size_t maxPacketDataSize);
54 
55  public:
57  PacketExtractResult tryExtractNextPacket(const Packet*& pExtractedPacket);
58 
60  void consume();
61 
62  private:
66  };
67 }}
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::ionet::PacketExtractResult::PACKET_EXTRACT_RESULT_LIST
catapult::ionet::Packet
A packet header with a data payload.
Definition: Packet.h:32
m_maxPacketDataSize
size_t m_maxPacketDataSize
Definition: PacketSocket.cpp:243
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::ionet::PacketHeader
A packet header that all transferable information is expected to have.
Definition: PacketHeader.h:30
Packet.h
PacketExtractor.h
catapult::ionet::IsPacketDataSizeValid
constexpr bool IsPacketDataSizeValid(const PacketHeader &header, size_t maxPacketDataSize)
Determines if header indicates a valid packet data size no greater than maxPacketDataSize.
Definition: PacketHeader.h:41
catapult::ionet::ByteBuffer
std::vector< uint8_t > ByteBuffer
Definition: IoTypes.h:28
catapult::ionet::PacketExtractor::PacketExtractor
PacketExtractor(ByteBuffer &data, size_t maxPacketDataSize)
Definition: PacketExtractor.cpp:27
catapult::ionet::PacketExtractor::m_maxPacketDataSize
size_t m_maxPacketDataSize
Definition: PacketExtractor.h:64
catapult::ionet::PacketExtractor::tryExtractNextPacket
PacketExtractResult tryExtractNextPacket(const Packet *&pExtractedPacket)
Tries to extract the next packet into (pExtractedPacket).
Definition: PacketExtractor.cpp:33
catapult::ionet::PacketExtractor::m_data
ByteBuffer & m_data
Definition: PacketExtractor.h:63
catapult::ionet::PacketExtractResult
PacketExtractResult
Possible results from PacketExtractor::tryExtractNextPacket.
Definition: PacketExtractor.h:40
catapult::ionet::operator<<
std::ostream & operator<<(std::ostream &out, ConnectionSecurityMode value)
Insertion operator for outputting value to out.
catapult::ionet::PacketExtractor::consume
void consume()
Marks all extracted packets as consumed and deletes their backing memory.
Definition: PacketExtractor.cpp:55
catapult::ionet::PacketExtractor::m_consumedBytes
size_t m_consumedBytes
Definition: PacketExtractor.h:65
catapult
Definition: AddressExtractionExtension.cpp:28
Logging.h
catapult::ionet::PacketExtractor
Helper for extracting a packet from a working buffer.
Definition: PacketExtractor.h:49
IoTypes.h