blob: de00a9755899286c8f7cc4b97f338f239d84d3a0 [file] [log] [blame]
Jeff Thompson2d28d492013-07-01 17:57:53 -07001/*
2 * Author: Jeff Thompson
3 *
4 * BSD license, See the LICENSE file for more information.
5 */
6
7#ifndef NDN_BINARYXMLENCODER_HPP
8#define NDN_BINARYXMLENCODER_HPP
9
10#include <cstdlib>
11#include <stdexcept>
12#include "../c/encoding/BinaryXMLEncoder.h"
13
14namespace ndn {
15
16/**
17 * A BinaryXMLEncoder wraps a C ndn_BinaryXMLEncoder struct and related functions.
18 */
19class BinaryXMLEncoder {
20public:
21 /**
22 * Initialize the base ndn_BinaryXMLEncoder struct with an initial array of 16 bytes. Use simpleRealloc.
23 */
24 BinaryXMLEncoder()
25 {
26 const unsigned int initialLength = 16;
27 ndn_BinaryXMLEncoder_init(&base_, (unsigned char *)malloc(initialLength), initialLength, simpleRealloc);
28 }
29
30 /**
31 * Wrap the C stdlib realloc to convert to/from void * to unsigned char *.
32 * @param array the allocated array buffer to realloc
33 * @param length the length for the new array buffer
34 * @return the new allocated array buffer
35 */
36 static unsigned char *simpleRealloc(unsigned char *array, unsigned int length)
37 {
38 return (unsigned char *)realloc(array, length);
39 }
40
41 /**
42 * Return a pointer to the base ndn_BinaryXMLEncoder struct.
43 * @return
44 */
45 struct ndn_BinaryXMLEncoder *getEncoder() { return &base_; }
46
47private:
48 struct ndn_BinaryXMLEncoder base_;
49};
50
51}
52
53#endif