You can implement a packet for your application in a .msg
file as follows:
cplusplus {{
#include "veins/modules/messages/WaveShortMessage_m.h"
}}
class WaveShortMessage;
message MyAppsPacket extends WaveShortMessage {
string sourceAddress;
string destinationAddress;
simtime_t sendingTime;
}
Then in your code you can use the built-in setByteLength()
. Use cPacket subclass for your messages because:
(cPacket is) A subclass of cMessage that can be used to represent packets
(frames, * datagrams, application messages, etc). cPacket adds length
(measured in * bits or bytes), bit error flag, and encapsulation
capability to cMessage. * Length and bit error flag are significant
when the packet travels through * a cDatarateChannel or another
channel that supports data rate and/or * error modelling. *
Related Q&A which shows the casting from cMessage
to cPacket
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…