blob: af495ca1f0f0d3b6df5fafae209edd6b423f8738 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07004 * See COPYING for copyright and distribution information.
Jeff Thompson2d28d492013-07-01 17:57:53 -07005 */
6
7#ifndef NDN_BINARYXMLENCODER_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_BINARYXMLENCODER_HPP
Jeff Thompson2d28d492013-07-01 17:57:53 -07009
Jeff Thompson58d798f2013-07-02 14:16:25 -070010#include <vector>
Jeff Thompsonb0979fd2013-07-30 15:48:21 -070011#include "../common.hpp"
Jeff Thompson10ad12a2013-09-24 16:19:11 -070012#include "../util/dynamic-uint8-vector.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -070013#include "../c/encoding/binary-xml-encoder.h"
Jeff Thompson2d28d492013-07-01 17:57:53 -070014
15namespace ndn {
16
17/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070018 * A BinaryXmlEncoder extends a C ndn_BinaryXmlEncoder struct and wraps related functions.
Jeff Thompson2d28d492013-07-01 17:57:53 -070019 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070020class BinaryXmlEncoder : public ndn_BinaryXmlEncoder {
Jeff Thompson2d28d492013-07-01 17:57:53 -070021public:
22 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070023 * Initialize the base ndn_BinaryXmlEncoder struct with an initial array of 16 bytes. Use simpleRealloc.
Jeff Thompson2d28d492013-07-01 17:57:53 -070024 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070025 BinaryXmlEncoder()
Jeff Thompsoneced5802013-08-12 13:34:52 -070026 : output_(16)
Jeff Thompson2d28d492013-07-01 17:57:53 -070027 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070028 ndn_BinaryXmlEncoder_initialize(this, &output_);
Jeff Thompson2d28d492013-07-01 17:57:53 -070029 }
30
31 /**
Jeff Thompsonf0570a62013-08-21 11:38:19 -070032 * 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 Thompson58d798f2013-07-02 14:16:25 -070034 */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070035 const ptr_lib::shared_ptr<std::vector<uint8_t> >&
Jeff Thompson0050abe2013-09-17 12:50:25 -070036 getOutput()
Jeff Thompson58d798f2013-07-02 14:16:25 -070037 {
Jeff Thompsonf0570a62013-08-21 11:38:19 -070038 output_.get()->resize(offset);
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070039 return output_.get();
Jeff Thompson58d798f2013-07-02 14:16:25 -070040 }
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070041
Jeff Thompson10ad12a2013-09-24 16:19:11 -070042 DynamicUInt8Vector output_;
Jeff Thompson2d28d492013-07-01 17:57:53 -070043};
44
45}
46
47#endif