blob: 33afb094834224b5fe3e01c2a1366dffef8f2b96 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson47eecfc2013-07-07 22:56:46 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson47eecfc2013-07-07 22:56:46 -07005 * See COPYING for copyright and distribution information.
Jeff Thompson2d28d492013-07-01 17:57:53 -07006 */
7
8#ifndef NDN_BINARYXMLENCODER_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07009#define NDN_BINARYXMLENCODER_HPP
Jeff Thompson2d28d492013-07-01 17:57:53 -070010
Jeff Thompson58d798f2013-07-02 14:16:25 -070011#include <vector>
Jeff Thompson25b4e612013-10-10 16:03:24 -070012#include <ndn-cpp/common.hpp>
Jeff Thompson10ad12a2013-09-24 16:19:11 -070013#include "../util/dynamic-uint8-vector.hpp"
Jeff Thompson53412192013-08-06 13:35:50 -070014#include "../c/encoding/binary-xml-encoder.h"
Jeff Thompson2d28d492013-07-01 17:57:53 -070015
16namespace ndn {
17
18/**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070019 * A BinaryXmlEncoder extends a C ndn_BinaryXmlEncoder struct and wraps related functions.
Jeff Thompson2d28d492013-07-01 17:57:53 -070020 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070021class BinaryXmlEncoder : public ndn_BinaryXmlEncoder {
Jeff Thompson2d28d492013-07-01 17:57:53 -070022public:
23 /**
Jeff Thompsonf0fea002013-07-30 17:22:42 -070024 * Initialize the base ndn_BinaryXmlEncoder struct with an initial array of 16 bytes. Use simpleRealloc.
Jeff Thompson2d28d492013-07-01 17:57:53 -070025 */
Jeff Thompsonf0fea002013-07-30 17:22:42 -070026 BinaryXmlEncoder()
Jeff Thompsoneced5802013-08-12 13:34:52 -070027 : output_(16)
Jeff Thompson2d28d492013-07-01 17:57:53 -070028 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070029 ndn_BinaryXmlEncoder_initialize(this, &output_);
Jeff Thompson2d28d492013-07-01 17:57:53 -070030 }
31
32 /**
Jeff Thompsonf0570a62013-08-21 11:38:19 -070033 * Resize the output vector to the correct encoding length and return.
34 * @return The encoding as a shared_ptr. Assume that the caller now owns the vector.
Jeff Thompson58d798f2013-07-02 14:16:25 -070035 */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070036 const ptr_lib::shared_ptr<std::vector<uint8_t> >&
Jeff Thompson0050abe2013-09-17 12:50:25 -070037 getOutput()
Jeff Thompson58d798f2013-07-02 14:16:25 -070038 {
Jeff Thompsonf0570a62013-08-21 11:38:19 -070039 output_.get()->resize(offset);
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070040 return output_.get();
Jeff Thompson58d798f2013-07-02 14:16:25 -070041 }
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070042
Jeff Thompson10ad12a2013-09-24 16:19:11 -070043 DynamicUInt8Vector output_;
Jeff Thompson2d28d492013-07-01 17:57:53 -070044};
45
46}
47
48#endif