binary-xml-encoder.h
1 
21 #ifndef NDN_BINARYXMLENCODER_H
22 #define NDN_BINARYXMLENCODER_H
23 
24 #include <ndn-cpp/c/errors.h>
25 #include "../util/dynamic-uint8-array.h"
26 #include "../util/blob.h"
27 #include "binary-xml.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
38  size_t offset;
39 };
40 
48 static __inline void ndn_BinaryXmlEncoder_initialize(struct ndn_BinaryXmlEncoder *self, struct ndn_DynamicUInt8Array *output)
49 {
50  self->output = output;
51  self->offset = 0;
52 }
53 
61 ndn_Error ndn_BinaryXmlEncoder_encodeTypeAndValue(struct ndn_BinaryXmlEncoder *self, unsigned int type, unsigned int value);
62 
69 static __inline ndn_Error ndn_BinaryXmlEncoder_writeElementStartDTag(struct ndn_BinaryXmlEncoder *self, unsigned int tag)
70 {
71  return ndn_BinaryXmlEncoder_encodeTypeAndValue(self, ndn_BinaryXml_DTAG, tag);
72 }
73 
79 ndn_Error ndn_BinaryXmlEncoder_writeElementClose(struct ndn_BinaryXmlEncoder *self);
80 
87 ndn_Error ndn_BinaryXmlEncoder_writeBlob(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value);
88 
97 ndn_Error ndn_BinaryXmlEncoder_writeBlobDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value);
98 
106 static __inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalBlobDTagElement
107  (struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
108 {
109  if (value->value && value->length > 0)
110  return ndn_BinaryXmlEncoder_writeBlobDTagElement(self, tag, value);
111  else
112  return NDN_ERROR_success;
113 }
114 
121 ndn_Error ndn_BinaryXmlEncoder_writeUData(struct ndn_BinaryXmlEncoder *self, struct ndn_Blob *value);
122 
131 ndn_Error ndn_BinaryXmlEncoder_writeUDataDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value);
132 
140 static __inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalUDataDTagElement
141  (struct ndn_BinaryXmlEncoder *self, unsigned int tag, struct ndn_Blob *value)
142 {
143  if (value->value && value->length > 0)
144  return ndn_BinaryXmlEncoder_writeUDataDTagElement(self, tag, value);
145  else
146  return NDN_ERROR_success;
147 }
148 
155 ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalInt(struct ndn_BinaryXmlEncoder *self, unsigned int value);
156 
166 ndn_Error ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, unsigned int value);
167 
175 static __inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, int value)
176 {
177  if (value >= 0)
178  return ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement(self, tag, (size_t)value);
179  else
180  return NDN_ERROR_success;
181 }
182 
190 ndn_Error ndn_BinaryXmlEncoder_writeAbsDoubleBigEndianBlob(struct ndn_BinaryXmlEncoder *self, double value);
191 
201 ndn_Error ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement(struct ndn_BinaryXmlEncoder *self, unsigned int tag, double milliseconds);
202 
210 static __inline ndn_Error ndn_BinaryXmlEncoder_writeOptionalTimeMillisecondsDTagElement
211  (struct ndn_BinaryXmlEncoder *self, unsigned int tag, double milliseconds)
212 {
213  if (milliseconds >= 0)
214  return ndn_BinaryXmlEncoder_writeTimeMillisecondsDTagElement(self, tag, milliseconds);
215  else
216  return NDN_ERROR_success;
217 }
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 
223 #endif
224 
Copyright (C) 2013-2015 Regents of the University of California.
Definition: binary-xml-encoder.h:36
size_t offset
the offset into output.array for the next encoding
Definition: binary-xml-encoder.h:38
size_t length
the number of bytes in value.
Definition: blob-types.h:35
A struct ndn_DynamicUInt8Array holds a pointer to an allocated array, the length of the allocated arr...
Definition: dynamic-uint8-array-types.h:40
struct ndn_DynamicUInt8Array * output
A pointer to a ndn_DynamicUInt8Array which receives the encoded output.
Definition: binary-xml-encoder.h:37
const uint8_t * value
pointer to the pre-allocated buffer for the value.
Definition: blob-types.h:34
Copyright (C) 2015 Regents of the University of California.
Definition: blob-types.h:33