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 | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef NDN_BINARYXMLENCODER_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_BINARYXMLENCODER_HPP |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 9 | #include <vector> |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 10 | #include "../common.hpp" |
Jeff Thompson | faaa237 | 2013-08-12 13:16:35 -0700 | [diff] [blame] | 11 | #include "../util/dynamic-uchar-vector.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 12 | #include "../c/encoding/binary-xml-encoder.h" |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 17 | * A BinaryXmlEncoder extends a C ndn_BinaryXmlEncoder struct and wraps related functions. |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 18 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 19 | class BinaryXmlEncoder : public ndn_BinaryXmlEncoder { |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 20 | public: |
| 21 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 22 | * Initialize the base ndn_BinaryXmlEncoder struct with an initial array of 16 bytes. Use simpleRealloc. |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 23 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 24 | BinaryXmlEncoder() |
Jeff Thompson | eced580 | 2013-08-12 13:34:52 -0700 | [diff] [blame] | 25 | : output_(16) |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 26 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 27 | ndn_BinaryXmlEncoder_initialize(this, &output_); |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /** |
Jeff Thompson | f0570a6 | 2013-08-21 11:38:19 -0700 | [diff] [blame] | 31 | * Resize the output vector to the correct encoding length and return. |
| 32 | * @return The encoding as a shared_ptr. Assume that the caller now owns the vector. |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 33 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame^] | 34 | const ptr_lib::shared_ptr<std::vector<unsigned char> >& getOutput() |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 35 | { |
Jeff Thompson | f0570a6 | 2013-08-21 11:38:19 -0700 | [diff] [blame] | 36 | output_.get()->resize(offset); |
Jeff Thompson | faaa237 | 2013-08-12 13:16:35 -0700 | [diff] [blame] | 37 | return output_.get(); |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 38 | } |
Jeff Thompson | faaa237 | 2013-08-12 13:16:35 -0700 | [diff] [blame] | 39 | |
| 40 | DynamicUCharVector output_; |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | } |
| 44 | |
| 45 | #endif |