INET Framework for OMNeT++/OMNEST
inet::serializer::ByteArraySerializer Class Reference

#include <SerializerBase.h>

Inheritance diagram for inet::serializer::ByteArraySerializer:
inet::serializer::SerializerBase

Public Member Functions

virtual void serialize (const cPacket *pkt, Buffer &b, Context &context) override
 Serializes a cPacket for transmission on the wire. More...
 
virtual cPacket * deserialize (const Buffer &b, Context &context) override
 Puts a packet sniffed from the wire into an EtherFrame. More...
 
- Public Member Functions inherited from inet::serializer::SerializerBase
 SerializerBase (const char *name=nullptr)
 
void serializePacket (const cPacket *pkt, Buffer &b, Context &context)
 
cPacket * deserializePacket (const Buffer &b, Context &context)
 

Additional Inherited Members

- Static Public Member Functions inherited from inet::serializer::SerializerBase
static SerializerBaselookupSerializer (const cPacket *pkt, Context &context, ProtocolGroup group, int id)
 
static void lookupAndSerialize (const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 
static SerializerBaselookupDeserializer (Context &context, ProtocolGroup group, int id)
 
static cPacket * lookupAndDeserialize (const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 

Member Function Documentation

cPacket * inet::serializer::ByteArraySerializer::deserialize ( const Buffer b,
Context context 
)
overridevirtual

Puts a packet sniffed from the wire into an EtherFrame.

Implements inet::serializer::SerializerBase.

Referenced by inet::serializer::IPv4Serializer::deserialize(), and inet::serializer::SerializerBase::deserializePacket().

147 {
148  RawPacket *bam = nullptr;
149  unsigned int bytes = b.getRemainingSize();
150  if (bytes) {
151  bam = new RawPacket("parsed-bytes");
152  bam->setDataFromBuffer(b.accessNBytes(bytes), bytes);
153  bam->setByteLength(bytes);
154  }
155  return bam;
156 }
value< double, units::m > b
Definition: Units.h:1054
void inet::serializer::ByteArraySerializer::serialize ( const cPacket *  pkt,
Buffer b,
Context context 
)
overridevirtual

Serializes a cPacket for transmission on the wire.

Returns the length of data written into buffer.

Implements inet::serializer::SerializerBase.

134 {
135  const RawPacket *bam = check_and_cast<const RawPacket *>(pkt);
136  unsigned int length = bam->getByteLength();
137  unsigned int wl = std::min(length, b.getRemainingSize());
138  wl = bam->copyDataToBuffer(b.accessNBytes(0), wl);
139  b.accessNBytes(wl);
140  if (length > wl)
141  b.fillNBytes(length - wl, '?');
142  if (pkt->getEncapsulatedPacket())
143  throw cRuntimeError("Serializer: encapsulated packet in ByteArrayPacket is not allowed");
144 }
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
value< double, units::m > b
Definition: Units.h:1054

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