Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 6 | #ifndef NDN_WIREFORMAT_HPP |
| 7 | #define NDN_WIREFORMAT_HPP |
| 8 | |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 9 | #include "../common.hpp" |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
| 12 | namespace ndn { |
| 13 | |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 14 | class Interest; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 15 | class Data; |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 16 | |
| 17 | class WireFormat { |
| 18 | public: |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 19 | virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest); |
Jeff Thompson | 4238071 | 2013-06-28 10:59:33 -0700 | [diff] [blame] | 20 | virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength); |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 22 | virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeData(const Data &data); |
| 23 | virtual void decodeData(Data &data, const unsigned char *input, unsigned int inputLength); |
Jeff Thompson | fa181ac | 2013-08-02 19:00:51 -0700 | [diff] [blame^] | 24 | |
| 25 | /** |
| 26 | * Set the static default WireFormat used by default encoding and decoding methods. |
| 27 | * @param wireFormat A Pointer to a object of a subclass of WireFormat. This does not make a copy and |
| 28 | * the caller must ensure that the object remains allocated. |
| 29 | */ |
| 30 | static void setDefaultWireFormat(WireFormat *wireFormat) |
| 31 | { |
| 32 | defaultWireFormat_ = wireFormat; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Return the default WireFormat used by default encoding and decoding methods which was set with |
| 37 | * setDefaultWireFormat. |
| 38 | * @return A pointer to the WireFormat object. |
| 39 | */ |
| 40 | static WireFormat *getDefaultWireFormat() |
| 41 | { |
| 42 | return defaultWireFormat_; |
| 43 | } |
| 44 | |
| 45 | private: |
| 46 | /** |
| 47 | * This is implemented by only one of the subclasses of WireFormat to return a new object used |
| 48 | * as the initial value for the default WireFormat. If the application doesn't include that class, then the application |
| 49 | * needs to include another subclass which defines WireFormat::newInitialDefaultWireFormat. |
| 50 | * @return a new object, which is held by a shared_ptr and freed when the application exits. |
| 51 | */ |
| 52 | static WireFormat *newInitialDefaultWireFormat(); |
| 53 | |
| 54 | /** |
| 55 | * Hold the result of newInitialDefaultWireFormat in this shared_ptr which is freed when the application exits. |
| 56 | */ |
| 57 | static ptr_lib::shared_ptr<WireFormat> initialDefaultWireFormat_; |
| 58 | |
| 59 | static WireFormat *defaultWireFormat_; |
Jeff Thompson | 9c41dfe | 2013-06-27 12:10:25 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | #endif |
| 65 | |