lp-packet-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_LPPACKETLITE_HPP
24 #define NDN_LPPACKETLITE_HPP
25 
26 #include "../util/blob-lite.hpp"
27 #include "incoming-face-id-lite.hpp"
28 #include "../network-nack-lite.hpp"
29 #include "../../c/lp/lp-packet-types.h"
30 
31 namespace ndn {
32 
34 public:
39  ndn_LpPacketHeaderFieldType
40  getType() const { return type; }
41 
47  const IncomingFaceIdLite&
48  getIncomingFaceId() const { return IncomingFaceIdLite::downCast(incomingFaceId); }
49 
51  getIncomingFaceId() { return IncomingFaceIdLite::downCast(incomingFaceId); }
52 
58  const NetworkNackLite&
59  getNetworkNack() const { return NetworkNackLite::downCast(networkNack); }
60 
62  getNetworkNack() { return NetworkNackLite::downCast(networkNack); }
63 
70  static LpPacketHeaderFieldLite&
71  downCast(ndn_LpPacketHeaderField& lpPacketHeaderField)
72  {
73  return *(LpPacketHeaderFieldLite*)&lpPacketHeaderField;
74  }
75 
76  static const LpPacketHeaderFieldLite&
77  downCast(const ndn_LpPacketHeaderField& lpPacketHeaderField)
78  {
79  return *(LpPacketHeaderFieldLite*)&lpPacketHeaderField;
80  }
81 };
82 
83 class LpPacketLite : private ndn_LpPacket {
84 public:
95 
100  const BlobLite&
102 
107  size_t
108  countHeaderFields() const { return nHeaderFields; }
109 
117  getHeaderField(int index) const
118  {
119  return LpPacketHeaderFieldLite::downCast(headerFields[index]);
120  }
121 
123  getHeaderField(int index)
124  {
125  return LpPacketHeaderFieldLite::downCast(headerFields[index]);
126  }
127 
133  void
135  {
136  BlobLite::downCast(this->fragmentWireEncoding) = fragmentWireEncoding;
137  }
138 
144  static LpPacketLite&
145  downCast(ndn_LpPacket& lpPacket) { return *(LpPacketLite*)&lpPacket; }
146 
147  static const LpPacketLite&
148  downCast(const ndn_LpPacket& lpPacket) { return *(LpPacketLite*)&lpPacket; }
149 
150 private:
151  // Declare friends who can downcast to the private base.
152  friend class Tlv0_1_1WireFormatLite;
153  friend class IncomingFaceIdLite;
154  friend class NetworkNackLite;
155 
160  LpPacketLite(const LpPacketLite& other);
161 
166  LpPacketLite& operator=(const LpPacketLite& other);
167 };
168 
169 }
170 
171 #endif
size_t maxHeaderFields
the number of elements in the allocated headerFields array.
Definition: lp-packet-types.h:61
ndn_LpPacketHeaderFieldType getType() const
Get the type of this header field.
Definition: lp-packet-lite.hpp:40
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
size_t countHeaderFields() const
Get the number of header fields.
Definition: lp-packet-lite.hpp:108
static LpPacketLite & downCast(ndn_LpPacket &lpPacket)
Downcast the reference to the ndn_LpPacket struct to an LpPacketLite.
Definition: lp-packet-lite.hpp:145
An ndn_LpPacketHeaderField holds a type and a union with values for the different types of LP packet ...
Definition: lp-packet-types.h:45
An ndn_LpPacket holds a list of LP packet header fields and an optional fragment wire encoding...
Definition: lp-packet-types.h:57
static LpPacketHeaderFieldLite & downCast(ndn_LpPacketHeaderField &lpPacketHeaderField)
Downcast the reference to the ndn_LpPacketHeaderField struct to an LpPacketHeaderFieldLite.
Definition: lp-packet-lite.hpp:71
Definition: lp-packet-lite.hpp:83
NetworkNackLite represents a network Nack packet and includes a Nack reason.
Definition: network-nack-lite.hpp:35
static BlobLite & downCast(ndn_Blob &blob)
Downcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:76
IncomingFaceIdLite represents the incoming face ID header field in an NDNLPv2 packet.
Definition: incoming-face-id-lite.hpp:37
Definition: lp-packet-lite.hpp:33
struct ndn_LpPacketHeaderField * headerFields
pointer to the array of ndn_LpPacketHeaderField.
Definition: lp-packet-types.h:60
static NetworkNackLite & downCast(ndn_NetworkNack &networkNack)
Downcast the reference to the ndn_NetworkNack struct to an NetworkNackLite.
Definition: network-nack-lite.hpp:96
size_t nHeaderFields
the number of header fields in the packet.
Definition: lp-packet-types.h:62
static IncomingFaceIdLite & downCast(ndn_IncomingFaceId &incomingFaceId)
Downcast the reference to the ndn_IncomingFaceId struct to an IncomingFaceIdLite. ...
Definition: incoming-face-id-lite.hpp:74
LpPacketLite(struct ndn_LpPacketHeaderField *headerFields, size_t maxHeaderFields)
Create an LpPacket to use the headerFieldsArray.
Definition: lp-packet-lite.cpp:28
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
const NetworkNackLite & getNetworkNack() const
Get this field as an NetworkNack.
Definition: lp-packet-lite.hpp:59
void setFragmentWireEncoding(const BlobLite &fragmentWireEncoding)
Set the fragment wire encoding.
Definition: lp-packet-lite.hpp:134
struct ndn_Blob fragmentWireEncoding
A Blob whose value is a pointer to a pre-allocated buffer for the fragment wire encoding.
Definition: lp-packet-types.h:58
const LpPacketHeaderFieldLite & getHeaderField(int index) const
Get the header field at the given index.
Definition: lp-packet-lite.hpp:117
const IncomingFaceIdLite & getIncomingFaceId() const
Get this field as an IncomingFaceId.
Definition: lp-packet-lite.hpp:48
const BlobLite & getFragmentWireEncoding() const
Get the fragment wire encoding.
Definition: lp-packet-lite.hpp:101