OMNet++中peek命令的作用是什么

What is the function of peek command in OMNet++

在 INET 开发人员指南中,我找到了以下 `peek`` 命令。谁能帮我解释一下 peek、peekAt、peekData、peekAllAsBytes 和 peekAtFront 之间的区别?

示例命令:

偷看

auto firstHalf = udpHeader->peek(B(0), B(4));

窥视数据

auto data = packet->peekData();

peekAllAsBytes

auto data = packet->peekAllAsBytes();

窥视

vector<Packet *> *Mac::fragment(Packet *packet, vector<b>& sizes)
{
auto offset = b(0); // start from the packet's beginning
auto fragments = new vector<Packet *>(); // result collection
for (auto size : sizes) { // for each received size do
auto fragment = new Packet("Fragment"); // header + data part +
˓→trailer
auto header = makeShared<MacHeader>(); // create new header
header->setFragmentOffset(offset); // set fragment offset for
˓→reassembly
fragment->insertAtFront(header); // insert header into fragment
**auto data = packet->peekAt(offset, size);**
}

窥视前方

const auto& hdr = packet->peekAtFront<MacHeaderBase>();

对于 peekAtFront,我知道它 returns 数据包的 header 部分。但是,我不明白“MacHeaderBase”的功能是什么。

谢谢。

src/inet/common/packet/Packet.hsrc/inet/common/packet/chunk/Chunk.h中对这些方法有一些解释:

  1. peek()
/**
 * Returns the designated part of the data represented by this chunk in the
 * requested representation. If the length is unspecified, then the length of
 * the result is chosen according to the internal representation. The result
 * is mutable iff the designated part is directly represented in this chunk
 * by a mutable chunk, otherwise the result is immutable.
 */
template <typename T>
const Ptr<T> peek(const Iterator& iterator, b length = b(-1), int flags = 0) const
  1. peekData()
 /**
  * Returns the whole data part (excluding front and back popped parts) in the
  * current representation. The length of the returned chunk is the same as
  * the value returned by getDataLength(). The flags parameter is a combination
  * of Chunk::PeekFlag enumeration members.
  */
 const Ptr<const Chunk> peekData(int flags = 0) const
  1. peekAllAsBytes()
/**
 * Returns the whole packet (including front and back popped parts) as a
 * sequence of bytes. The length of the returned chunk is the same as the
 * value returned by getTotalLength(). The flags parameter is a combination
 * of Chunk::PeekFlag enumeration members.
 */
const Ptr<const BytesChunk> peekAllAsBytes(int flags = 0) const
  1. peekAt()
/**
* Returns the designated part of the packet as an immutable chunk in its
* current representation. If the length is unspecified, then the length of
* the result is chosen according to the current representation. The flags
* parameter is a combination of Chunk::PeekFlag enumeration members.
*/
const Ptr<const Chunk> peekAt(b offset, b length = b(-1), int flags = 0) const;
  1. peekAtFront()
/**
 * Returns the designated part as an immutable chunk in its current
 * representation. If the length is unspecified, then the length of the
 * result is chosen according to the current representation. The flags
 * parameter is a combination of Chunk::PeekFlag enumeration members.
 */
 const Ptr<const Chunk> peekAtFront(b length = b(-1), int flags = 0) const;

MacHeaderBase 是在 src/inet/linklayer/base/MacHeaderBase.msg.

中定义的 class