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 ControlParameters;
34 class ControlResponse;
35 class Signature;
36 class DelegationSet;
37 class EncryptedContent;
38 
39 class WireFormat {
40 public:
47  virtual Blob
48  encodeName(const Name& name);
49 
57  virtual void
58  decodeName(Name& name, const uint8_t *input, size_t inputLength);
59 
78  virtual Blob
80  (const Interest& interest, size_t *signedPortionBeginOffset,
81  size_t *signedPortionEndOffset);
82 
89  Blob
90  encodeInterest(const Interest& interest)
91  {
92  size_t dummyBeginOffset, dummyEndOffset;
93  return encodeInterest(interest, &dummyBeginOffset, &dummyEndOffset);
94  }
95 
117  virtual void
119  (Interest& interest, const uint8_t *input, size_t inputLength,
120  size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
121 
122  void
123  decodeInterest(Interest& interest, const uint8_t *input, size_t inputLength)
124  {
125  size_t dummyBeginOffset, dummyEndOffset;
127  (interest, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
128  }
129 
140  virtual Blob
141  encodeData
142  (const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
143 
150  Blob
151  encodeData(const Data& data)
152  {
153  size_t dummyBeginOffset, dummyEndOffset;
154  return encodeData(data, &dummyBeginOffset, &dummyEndOffset);
155  }
156 
170  virtual void
171  decodeData
172  (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset);
173 
174  void
175  decodeData(Data& data, const uint8_t *input, size_t inputLength)
176  {
177  size_t dummyBeginOffset, dummyEndOffset;
178  decodeData(data, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
179  }
180 
188  virtual Blob
189  encodeControlParameters(const ControlParameters& controlParameters);
190 
200  virtual void
202  (ControlParameters& controlParameters, const uint8_t *input,
203  size_t inputLength);
204 
212  virtual Blob
213  encodeControlResponse(const ControlResponse& controlResponse);
214 
224  virtual void
226  (ControlResponse& controlResponse, const uint8_t *input,
227  size_t inputLength);
228 
236  virtual Blob
237  encodeSignatureInfo(const Signature& signature);
238 
248  virtual Blob
249  encodeSignatureValue(const Signature& signature);
250 
262  virtual ptr_lib::shared_ptr<Signature>
264  (const uint8_t *signatureInfo, size_t signatureInfoLength,
265  const uint8_t *signatureValue, size_t signatureValueLength);
266 
274  virtual ptr_lib::shared_ptr<Signature>
276  (const Blob& signatureInfo, const Blob& signatureValue)
277  {
279  (signatureInfo.buf(), signatureInfo.size(), signatureValue.buf(),
280  signatureValue.size());
281  }
282 
290  virtual Blob
291  encodeDelegationSet(const DelegationSet& delegationSet);
292 
301  virtual void
303  (DelegationSet& delegationSet, const uint8_t *input, size_t inputLength);
304 
312  virtual Blob
313  encodeEncryptedContent(const EncryptedContent& encryptedContent);
314 
324  virtual void
326  (EncryptedContent& encryptedContent, const uint8_t *input,
327  size_t inputLength);
328 
334  static void
336  {
337  defaultWireFormat_ = wireFormat;
338  }
339 
345  static WireFormat*
347 
348 private:
355  static WireFormat*
356  newInitialDefaultWireFormat();
357 
358  static WireFormat *defaultWireFormat_;
359 };
360 
361 }
362 
363 #endif
364 
virtual Blob encodeName(const Name &name)
Encode name and return the encoding.
Definition: wire-format.cpp:47
virtual void decodeControlResponse(ControlResponse &controlResponse, const uint8_t *input, size_t inputLength)
Decode input as a control response and set the fields of the controlResponse object.
Definition: wire-format.cpp:110
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
virtual void decodeDelegationSet(DelegationSet &delegationSet, const uint8_t *input, size_t inputLength)
Decode input as a delegation set and set the fields of the delegationSet object.
Definition: wire-format.cpp:144
virtual Blob encodeSignatureInfo(const Signature &signature)
Encode signature as a SignatureInfo and return the encoding.
Definition: wire-format.cpp:117
Definition: data.hpp:37
Blob encodeData(const Data &data)
Encode data and return the encoding.
Definition: wire-format.hpp:151
An EncryptedContent holds an encryption type, a payload and other fields representing encrypted conte...
Definition: encrypted-content.hpp:37
virtual Blob encodeInterest(const Interest &interest, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Encode interest and return the encoding.
Definition: wire-format.cpp:61
virtual Blob encodeDelegationSet(const DelegationSet &delegationSet)
Encode delegationSet and return the encoding.
Definition: wire-format.cpp:137
virtual Blob encodeControlResponse(const ControlResponse &controlResponse)
Encode controlResponse and return the encoding.
Definition: wire-format.cpp:103
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:40
A DelegationSet holds a list of DelegationSet::Delegation entries which is used as the content of a L...
Definition: delegation-set.hpp:38
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:159
virtual Blob encodeControlParameters(const ControlParameters &controlParameters)
Encode controlParameters and return the encoding.
Definition: wire-format.cpp:89
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
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:54
virtual void decodeControlParameters(ControlParameters &controlParameters, const uint8_t *input, size_t inputLength)
Decode input as a control parameters and set the fields of the controlParameters object.
Definition: wire-format.cpp:96
virtual Blob encodeData(const Data &data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
Encode data and return the encoding.
Definition: wire-format.cpp:76
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:83
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
virtual void decodeEncryptedContent(EncryptedContent &encryptedContent, const uint8_t *input, size_t inputLength)
Decode input as an EncryptedContent and set the fields of the encryptedContent object.
Definition: wire-format.cpp:157
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:335
Definition: wire-format.hpp:39
Blob encodeInterest(const Interest &interest)
Encode interest and return the encoding.
Definition: wire-format.hpp:90
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:69
virtual Blob encodeEncryptedContent(const EncryptedContent &encryptedContent)
Encode encryptedContent and return the encoding.
Definition: wire-format.cpp:150