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 |
| 7 | #define NDN_BINARYXMLENCODER_HPP |
| 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 | 4554509 | 2013-07-16 18:36:26 -0700 | [diff] [blame] | 11 | #include "../c/util/ndn_realloc.h" |
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 | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 25 | { |
| 26 | const unsigned int initialLength = 16; |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 27 | ndn_BinaryXmlEncoder_init(this, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc); |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /** |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 31 | * Return the output as a shared_ptr. |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 32 | */ |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 33 | ptr_lib::shared_ptr<std::vector<unsigned char> > getOutput() |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 34 | { |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 35 | return ptr_lib::shared_ptr<std::vector<unsigned char> >(new std::vector<unsigned char>(output.array, output.array + offset)); |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 36 | } |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | #endif |