wire-format.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_WIREFORMAT_HPP
23 #define NDN_WIREFORMAT_HPP
24 
25 #include "../common.hpp"
26 #include "../util/blob.hpp"
27 
28 namespace ndn {
29 
30 class Name;
31 class Interest;
32 class Data;
33 class ForwardingEntry;
34 class ControlParameters;
35 class Signature;
36 
37 class WireFormat {
38 public:
44  static bool ENABLE_NDNX;
45 
52  virtual Blob
53  encodeName(const Name& name);
54 
62  virtual void
63  decodeName(Name& name, const uint8_t *input, size_t inputLength);
64 
83  virtual Blob
85  (const Interest& interest, size_t *signedPortionBeginOffset,
86  size_t *signedPortionEndOffset);
87 
94  Blob
95  encodeInterest(const Interest& interest)
96  {
97  size_t dummyBeginOffset, dummyEndOffset;
98  return encodeInterest(interest, &dummyBeginOffset, &dummyEndOffset);
99  }
100 
122  virtual void
124  (Interest& interest, const uint8_t *input, size_t inputLength,
125  size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
126 
127  void
128  decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength)
129  {
130  size_t dummyBeginOffset, dummyEndOffset;
132  (interest, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
133  }
134 
145  virtual Blob
146  encodeData
147  (const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
148 
155  Blob
156  encodeData(const Data& data)
157  {
158  size_t dummyBeginOffset, dummyEndOffset;
159  return encodeData(data, &dummyBeginOffset, &dummyEndOffset);
160  }
161 
175  virtual void
176  decodeData
177  (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
178 
179  void
180  decodeData(Data& data, const uint8_t *input, size_t inputLength)
181  {
182  size_t dummyBeginOffset, dummyEndOffset;
183  decodeData(data, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
184  }
185 
192  virtual Blob
193  encodeForwardingEntry(const ForwardingEntry& forwardingEntry);
194 
202  virtual void
203  decodeForwardingEntry(ForwardingEntry& forwardingEntry, const uint8_t *input, size_t inputLength);
204 
212  virtual Blob
214  (const ControlParameters& controlParameters);
215 
225  virtual void
227  (ControlParameters& controlParameters, const uint8_t *input,
228  size_t inputLength);
229 
237  virtual Blob
238  encodeSignatureInfo(const Signature& signature);
239 
251  virtual ptr_lib::shared_ptr<Signature>
253  (const uint8_t *signatureInfo, size_t signatureInfoLength,
254  const uint8_t *signatureValue, size_t signatureValueLength);
255 
263  virtual ptr_lib::shared_ptr<Signature>
265  (const Blob& signatureInfo, const Blob& signatureValue)
266  {
268  (signatureInfo.buf(), signatureInfo.size(), signatureValue.buf(),
269  signatureValue.size());
270  }
271 
281  virtual Blob
282  encodeSignatureValue(const Signature& signature);
283 
289  static void
291  {
292  defaultWireFormat_ = wireFormat;
293  }
294 
300  static WireFormat*
302 
303 private:
310  static WireFormat*
311  newInitialDefaultWireFormat();
312 
313  static WireFormat *defaultWireFormat_;
314 };
315 
316 }
317 
318 #endif
319 
virtual Blob encodeName(const Name &name)
Encode name and return the encoding.
Definition: wire-format.cpp:49
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
virtual Blob encodeSignatureInfo(const Signature &signature)
Encode signature as a SignatureInfo and return the encoding.
Definition: wire-format.cpp:117
Definition: data.hpp:36
Blob encodeData(const Data &data)
Encode data and return the encoding.
Definition: wire-format.hpp:156
virtual Blob encodeInterest(const Interest &interest, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Encode interest and return the encoding.
Definition: wire-format.cpp:63
virtual ptr_lib::shared_ptr< Signature > decodeSignatureInfoAndValue(const uint8_t *signatureInfo, size_t signatureInfoLength, const uint8_t *signatureValue, size_t signatureValueLength)
Decode signatureInfo as a signature info and signatureValue as the related SignatureValue, and return a new object which is a subclass of Signature.
Definition: wire-format.cpp:124
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
A Signature is an abstract base class providing methods to work with the signature information in a D...
Definition: signature.hpp:36
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:138
virtual Blob encodeControlParameters(const ControlParameters &controlParameters)
Encode controlParameters and return the encoding.
Definition: wire-format.cpp:103
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:126
virtual void decodeName(Name &name, const uint8_t *input, size_t inputLength)
Decode input as a name and set the fields of the Name object.
Definition: wire-format.cpp:56
virtual void decodeControlParameters(ControlParameters &controlParameters, const uint8_t *input, size_t inputLength)
Decode input as a command parameters and set the fields of the controlParameters object.
Definition: wire-format.cpp:110
virtual Blob encodeData(const Data &data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Encode data and return the encoding.
Definition: wire-format.cpp:78
virtual void decodeData(Data &data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Decode input as a data packet and set the fields in the data object.
Definition: wire-format.cpp:85
virtual Blob encodeForwardingEntry(const ForwardingEntry &forwardingEntry)
Encode forwardingEntry and return the encoding.
Definition: wire-format.cpp:91
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:36
virtual Blob encodeSignatureValue(const Signature &signature)
Encode the signatureValue in the Signature object as a SignatureValue (the signature bits) and return...
Definition: wire-format.cpp:131
static void setDefaultWireFormat(WireFormat *wireFormat)
Set the static default WireFormat used by default encoding and decoding methods.
Definition: wire-format.hpp:290
Definition: wire-format.hpp:37
Blob encodeInterest(const Interest &interest)
Encode interest and return the encoding.
Definition: wire-format.hpp:95
static bool ENABLE_NDNX
NDNx support and binary XML (ccnb or ndnb) encoding is deprecated and code with throw an exception...
Definition: wire-format.hpp:44
virtual void decodeForwardingEntry(ForwardingEntry &forwardingEntry, const uint8_t *input, size_t inputLength)
Decode input as a forwarding entry and set the fields of the forwardingEntry object.
Definition: wire-format.cpp:97
virtual void decodeInterest(Interest &interest, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Decode input as an interest and set the fields of the interest object.
Definition: wire-format.cpp:71