blob: 32bf82f4d75e6207203b2262df23e42197d9baa7 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07004 */
5
Jeff Thompson9c41dfe2013-06-27 12:10:25 -07006#ifndef NDN_WIREFORMAT_HPP
7#define NDN_WIREFORMAT_HPP
8
Jeff Thompsonb0979fd2013-07-30 15:48:21 -07009#include "../common.hpp"
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070010#include <vector>
11
12namespace ndn {
13
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070014class Interest;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070015class Data;
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070016
17class WireFormat {
18public:
Jeff Thompsonb0979fd2013-07-30 15:48:21 -070019 virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
Jeff Thompson42380712013-06-28 10:59:33 -070020 virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070021
Jeff Thompson56ec9e22013-08-02 11:34:07 -070022 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 Thompsonfa181ac2013-08-02 19:00:51 -070024
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 */
Jeff Thompson535f21a2013-08-05 18:25:46 -070040 static WireFormat *getDefaultWireFormat();
Jeff Thompsonfa181ac2013-08-02 19:00:51 -070041
42private:
43 /**
44 * This is implemented by only one of the subclasses of WireFormat to return a new object used
45 * as the initial value for the default WireFormat. If the application doesn't include that class, then the application
46 * needs to include another subclass which defines WireFormat::newInitialDefaultWireFormat.
47 * @return a new object, which is held by a shared_ptr and freed when the application exits.
48 */
49 static WireFormat *newInitialDefaultWireFormat();
50
Jeff Thompsonfa181ac2013-08-02 19:00:51 -070051 static WireFormat *defaultWireFormat_;
Jeff Thompson9c41dfe2013-06-27 12:10:25 -070052};
53
54}
55
56#endif
57