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