blob: 6ae391325cc203aace8ab2a87a6ef8a567ead237 [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>
Yingdi Yu61ec2722014-01-20 14:22:32 -080012#include <ndn-cpp-dev/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 Thompsonfda38f52013-12-10 18:13:37 -080024 * 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 Thompson2d28d492013-07-01 17:57:53 -070026 */
Jeff Thompsonfda38f52013-12-10 18:13:37 -080027 BinaryXmlEncoder(size_t initialLength = 16)
Jeff Thompsoneced5802013-08-12 13:34:52 -070028 : output_(16)
Jeff Thompson2d28d492013-07-01 17:57:53 -070029 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070030 ndn_BinaryXmlEncoder_initialize(this, &output_);
Jeff Thompson2d28d492013-07-01 17:57:53 -070031 }
32
33 /**
Jeff Thompsonf0570a62013-08-21 11:38:19 -070034 * 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 Thompson58d798f2013-07-02 14:16:25 -070036 */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070037 const ptr_lib::shared_ptr<std::vector<uint8_t> >&
Jeff Thompson0050abe2013-09-17 12:50:25 -070038 getOutput()
Jeff Thompson58d798f2013-07-02 14:16:25 -070039 {
Jeff Thompsonf0570a62013-08-21 11:38:19 -070040 output_.get()->resize(offset);
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070041 return output_.get();
Jeff Thompson58d798f2013-07-02 14:16:25 -070042 }
Jeff Thompsonfaaa2372013-08-12 13:16:35 -070043
Jeff Thompson10ad12a2013-09-24 16:19:11 -070044 DynamicUInt8Vector output_;
Jeff Thompson2d28d492013-07-01 17:57:53 -070045};
46
47}
48
49#endif