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 | 4554509 | 2013-07-16 18:36:26 -0700 | [diff] [blame] | 10 | #include "../c/util/ndn_realloc.h" |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 11 | #include "../c/encoding/BinaryXMLEncoder.h" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
Jeff Thompson | 0adcbea | 2013-07-15 16:29:52 -0700 | [diff] [blame] | 16 | * A BinaryXMLEncoder extends a C ndn_BinaryXMLEncoder struct and wraps related functions. |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 17 | */ |
Jeff Thompson | 0adcbea | 2013-07-15 16:29:52 -0700 | [diff] [blame] | 18 | class BinaryXMLEncoder : public ndn_BinaryXMLEncoder { |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 19 | public: |
| 20 | /** |
| 21 | * Initialize the base ndn_BinaryXMLEncoder struct with an initial array of 16 bytes. Use simpleRealloc. |
| 22 | */ |
| 23 | BinaryXMLEncoder() |
| 24 | { |
| 25 | const unsigned int initialLength = 16; |
Jeff Thompson | 4554509 | 2013-07-16 18:36:26 -0700 | [diff] [blame] | 26 | ndn_BinaryXMLEncoder_init(this, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc); |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | /** |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 30 | * Copy the encoded bytes to the end of the buffer. |
| 31 | * @param buffer a vector to receive the copy |
| 32 | */ |
| 33 | void appendTo(std::vector<unsigned char> &buffer) |
| 34 | { |
Jeff Thompson | 66f6c9a | 2013-07-15 16:33:22 -0700 | [diff] [blame] | 35 | buffer.insert(buffer.end(), 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 |