Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47eecfc | 2013-07-07 22:56:46 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef NDN_BINARYXMLENCODER_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_BINARYXMLENCODER_HPP |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 10 | #include <vector> |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 11 | #include "../common.hpp" |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 12 | #include "../util/dynamic-uint8-vector.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 13 | #include "../c/encoding/binary-xml-encoder.h" |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 18 | * A BinaryXmlEncoder extends a C ndn_BinaryXmlEncoder struct and wraps related functions. |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 19 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 20 | class BinaryXmlEncoder : public ndn_BinaryXmlEncoder { |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 21 | public: |
| 22 | /** |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 23 | * 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] | 24 | */ |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 25 | BinaryXmlEncoder() |
Jeff Thompson | eced580 | 2013-08-12 13:34:52 -0700 | [diff] [blame] | 26 | : output_(16) |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 27 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 28 | ndn_BinaryXmlEncoder_initialize(this, &output_); |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /** |
Jeff Thompson | f0570a6 | 2013-08-21 11:38:19 -0700 | [diff] [blame] | 32 | * Resize the output vector to the correct encoding length and return. |
| 33 | * @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] | 34 | */ |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 35 | const ptr_lib::shared_ptr<std::vector<uint8_t> >& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 36 | getOutput() |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 37 | { |
Jeff Thompson | f0570a6 | 2013-08-21 11:38:19 -0700 | [diff] [blame] | 38 | output_.get()->resize(offset); |
Jeff Thompson | faaa237 | 2013-08-12 13:16:35 -0700 | [diff] [blame] | 39 | return output_.get(); |
Jeff Thompson | 58d798f | 2013-07-02 14:16:25 -0700 | [diff] [blame] | 40 | } |
Jeff Thompson | faaa237 | 2013-08-12 13:16:35 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 42 | DynamicUInt8Vector output_; |
Jeff Thompson | 2d28d49 | 2013-07-01 17:57:53 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | } |
| 46 | |
| 47 | #endif |