All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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 "congestion-mark-lite.hpp"
30 #include "../../c/lp/lp-packet-types.h"
31 
32 namespace ndn {
33 
35 public:
40  ndn_LpPacketHeaderFieldType
41  getType() const { return type; }
42 
48  const IncomingFaceIdLite&
49  getIncomingFaceId() const { return IncomingFaceIdLite::downCast(incomingFaceId); }
50 
52  getIncomingFaceId() { return IncomingFaceIdLite::downCast(incomingFaceId); }
53 
59  const NetworkNackLite&
60  getNetworkNack() const { return NetworkNackLite::downCast(networkNack); }
61 
63  getNetworkNack() { return NetworkNackLite::downCast(networkNack); }
64 
70  const CongestionMarkLite&
71  getCongestionMark() const { return CongestionMarkLite::downCast(congestionMark); }
72 
74  getCongestionMark() { return CongestionMarkLite::downCast(congestionMark); }
75 
82  static LpPacketHeaderFieldLite&
83  downCast(ndn_LpPacketHeaderField& lpPacketHeaderField)
84  {
85  return *(LpPacketHeaderFieldLite*)&lpPacketHeaderField;
86  }
87 
88  static const LpPacketHeaderFieldLite&
89  downCast(const ndn_LpPacketHeaderField& lpPacketHeaderField)
90  {
91  return *(LpPacketHeaderFieldLite*)&lpPacketHeaderField;
92  }
93 };
94 
95 class LpPacketLite : private ndn_LpPacket {
96 public:
107 
112  const BlobLite&
114 
119  size_t
120  countHeaderFields() const { return nHeaderFields; }
121 
129  getHeaderField(int index) const
130  {
131  return LpPacketHeaderFieldLite::downCast(headerFields[index]);
132  }
133 
135  getHeaderField(int index)
136  {
137  return LpPacketHeaderFieldLite::downCast(headerFields[index]);
138  }
139 
145  void
147  {
148  BlobLite::downCast(this->fragmentWireEncoding) = fragmentWireEncoding;
149  }
150 
156  static LpPacketLite&
157  downCast(ndn_LpPacket& lpPacket) { return *(LpPacketLite*)&lpPacket; }
158 
159  static const LpPacketLite&
160  downCast(const ndn_LpPacket& lpPacket) { return *(LpPacketLite*)&lpPacket; }
161 
162 private:
163  // Declare friends who can downcast to the private base.
164  friend class Tlv0_2WireFormatLite;
165  friend class IncomingFaceIdLite;
166  friend class NetworkNackLite;
167  friend class CongestionMarkLite;
168 
173  LpPacketLite(const LpPacketLite& other);
174 
179  LpPacketLite& operator=(const LpPacketLite& other);
180 };
181 
182 }
183 
184 #endif
size_t maxHeaderFields
the number of elements in the allocated headerFields array.
Definition: lp-packet-types.h:64
ndn_LpPacketHeaderFieldType getType() const
Get the type of this header field.
Definition: lp-packet-lite.hpp:41
const CongestionMarkLite & getCongestionMark() const
Get this field as a CongestionMark.
Definition: lp-packet-lite.hpp:71
size_t countHeaderFields() const
Get the number of header fields.
Definition: lp-packet-lite.hpp:120
static LpPacketLite & downCast(ndn_LpPacket &lpPacket)
Downcast the reference to the ndn_LpPacket struct to an LpPacketLite.
Definition: lp-packet-lite.hpp:157
An ndn_LpPacketHeaderField holds a type and a union with values for the different types of LP packet ...
Definition: lp-packet-types.h:47
An ndn_LpPacket holds a list of LP packet header fields and an optional fragment wire encoding...
Definition: lp-packet-types.h:60
static LpPacketHeaderFieldLite & downCast(ndn_LpPacketHeaderField &lpPacketHeaderField)
Downcast the reference to the ndn_LpPacketHeaderField struct to an LpPacketHeaderFieldLite.
Definition: lp-packet-lite.hpp:83
Definition: lp-packet-lite.hpp:95
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:86
static CongestionMarkLite & downCast(ndn_CongestionMark &congestionMark)
Downcast the reference to the ndn_CongestionMark struct to an CongestionMarkLite. ...
Definition: congestion-mark-lite.hpp:73
IncomingFaceIdLite represents the incoming face ID header field in an NDNLPv2 packet.
Definition: incoming-face-id-lite.hpp:37
Definition: lp-packet-lite.hpp:34
CongestionMarkLite represents the congestion mark header field in an NDNLPv2 packet.
Definition: congestion-mark-lite.hpp:36
struct ndn_LpPacketHeaderField * headerFields
pointer to the array of ndn_LpPacketHeaderField.
Definition: lp-packet-types.h:63
static NetworkNackLite & downCast(ndn_NetworkNack &networkNack)
Downcast the reference to the ndn_NetworkNack struct to an NetworkNackLite.
Definition: network-nack-lite.hpp:97
size_t nHeaderFields
the number of header fields in the packet.
Definition: lp-packet-types.h:65
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:60
void setFragmentWireEncoding(const BlobLite &fragmentWireEncoding)
Set the fragment wire encoding.
Definition: lp-packet-lite.hpp:146
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:61
const LpPacketHeaderFieldLite & getHeaderField(int index) const
Get the header field at the given index.
Definition: lp-packet-lite.hpp:129
const IncomingFaceIdLite & getIncomingFaceId() const
Get this field as an IncomingFaceId.
Definition: lp-packet-lite.hpp:49
const BlobLite & getFragmentWireEncoding() const
Get the fragment wire encoding.
Definition: lp-packet-lite.hpp:113