blob: a879963e5f72a17001e191c20b9920925c327b64 [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson2d28d492013-07-01 17:57:53 -07004 */
5
6#ifndef NDN_BINARYXMLENCODER_HPP
7#define NDN_BINARYXMLENCODER_HPP
8
9#include <cstdlib>
Jeff Thompson58d798f2013-07-02 14:16:25 -070010#include <vector>
Jeff Thompson2d28d492013-07-01 17:57:53 -070011#include "../c/encoding/BinaryXMLEncoder.h"
12
13namespace ndn {
14
15/**
Jeff Thompson0adcbea2013-07-15 16:29:52 -070016 * A BinaryXMLEncoder extends a C ndn_BinaryXMLEncoder struct and wraps related functions.
Jeff Thompson2d28d492013-07-01 17:57:53 -070017 */
Jeff Thompson0adcbea2013-07-15 16:29:52 -070018class BinaryXMLEncoder : public ndn_BinaryXMLEncoder {
Jeff Thompson2d28d492013-07-01 17:57:53 -070019public:
20 /**
21 * Initialize the base ndn_BinaryXMLEncoder struct with an initial array of 16 bytes. Use simpleRealloc.
22 */
23 BinaryXMLEncoder()
24 {
25 const unsigned int initialLength = 16;
Jeff Thompson0adcbea2013-07-15 16:29:52 -070026 ndn_BinaryXMLEncoder_init(this, (unsigned char *)malloc(initialLength), initialLength, simpleRealloc);
Jeff Thompson2d28d492013-07-01 17:57:53 -070027 }
28
29 /**
30 * Wrap the C stdlib realloc to convert to/from void * to unsigned char *.
31 * @param array the allocated array buffer to realloc
32 * @param length the length for the new array buffer
33 * @return the new allocated array buffer
34 */
35 static unsigned char *simpleRealloc(unsigned char *array, unsigned int length)
36 {
37 return (unsigned char *)realloc(array, length);
38 }
39
40 /**
Jeff Thompson58d798f2013-07-02 14:16:25 -070041 * Copy the encoded bytes to the end of the buffer.
42 * @param buffer a vector to receive the copy
43 */
44 void appendTo(std::vector<unsigned char> &buffer)
45 {
Jeff Thompson66f6c9a2013-07-15 16:33:22 -070046 buffer.insert(buffer.end(), output.array, output.array + offset);
Jeff Thompson58d798f2013-07-02 14:16:25 -070047 }
Jeff Thompson2d28d492013-07-01 17:57:53 -070048};
49
50}
51
52#endif