Added readElementClose and peekDTag
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.c b/ndn-cpp/encoding/BinaryXMLDecoder.c
index 2e4e103..89f6a9c 100644
--- a/ndn-cpp/encoding/BinaryXMLDecoder.c
+++ b/ndn-cpp/encoding/BinaryXMLDecoder.c
@@ -31,7 +31,7 @@
return (char *)0;
}
-char *ndn_BinaryXMLDecoder_readDTag(struct ndn_BinaryXMLDecoder *self, unsigned int tag)
+char *ndn_BinaryXMLDecoder_readDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag)
{
char *error;
unsigned int type;
@@ -42,8 +42,41 @@
if (type != ndn_BinaryXML_DTAG)
return "ndn_BinaryXMLDecoder_readDTag: header type is not a DTAG";
- if (value != tag)
+ if (value != expectedTag)
return "ndn_BinaryXMLDecoder_readDTag: did not get the expected DTAG";
return (char *)0;
+}
+
+char *ndn_BinaryXMLDecoder_readElementClose(struct ndn_BinaryXMLDecoder *self)
+{
+ if (self->offset >= self->inputLength)
+ return "ndn_BinaryXMLDecoder_readElementClose read past the end of the input";
+
+ unsigned int octet = (unsigned int)(self->input[self->offset++] & 0xff);
+
+ if (octet != ndn_BinaryXML_CLOSE)
+ return "ndn_BinaryXMLDecoder_readDTag: did not get the expected element close";
+
+ return (char *)0;
+}
+
+char *ndn_BinaryXMLDecoder_peekDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *gotExpectedTag)
+{
+ // Default to 0.
+ *gotExpectedTag = 0;
+
+ unsigned int type;
+ unsigned int value;
+ unsigned int saveOffset = self->offset;
+ char *error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value);
+ self->offset = saveOffset;
+
+ if (error)
+ return error;
+
+ if (type == ndn_BinaryXML_DTAG && value == expectedTag)
+ *gotExpectedTag = 1;
+
+ return (char *)0;
}
\ No newline at end of file
diff --git a/ndn-cpp/encoding/BinaryXMLDecoder.h b/ndn-cpp/encoding/BinaryXMLDecoder.h
index 470e562..ed24df7 100644
--- a/ndn-cpp/encoding/BinaryXMLDecoder.h
+++ b/ndn-cpp/encoding/BinaryXMLDecoder.h
@@ -30,18 +30,35 @@
* @param self pointer to the ndn_BinaryXMLDecoder struct
* @param type output for the header type
* @param value output for the header value
- * @return 0 for success, else an error string
+ * @return 0 for success, else an error string for read past the end of the input
*/
char *ndn_BinaryXMLDecoder_decodeTypeAndValue(struct ndn_BinaryXMLDecoder *self, unsigned int *type, unsigned int *value);
/**
- * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be the
- * given tag. Update offset.
+ * Decode the header from self's input starting at offset, expecting the type to be DTAG and the value to be expectedTag.
+ * Update offset.
* @param self pointer to the ndn_BinaryXMLDecoder struct
- * @param tag the expected value for DTAG
+ * @param expectedTag the expected value for DTAG
* @return 0 for success, else an error string, including an error if not the expected tag
*/
-char *ndn_BinaryXMLDecoder_readDTag(struct ndn_BinaryXMLDecoder *self, unsigned int tag);
+char *ndn_BinaryXMLDecoder_readDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag);
+
+/**
+ * Read one byte from self's input starting at offset, expecting it to be the element close.
+ * @param self pointer to the ndn_BinaryXMLDecoder struct
+ * @return 0 for success, else an error string, including an error if not the element close
+ */
+char *ndn_BinaryXMLDecoder_readElementClose(struct ndn_BinaryXMLDecoder *self);
+
+/**
+ * Decode the header from self's input starting at offset, and if it is a DTAG where the value is the expectedTag,
+ * then set gotExpectedTag to 1, else 0. Do not update offset, including if returning an error.
+ * @param self pointer to the ndn_BinaryXMLDecoder struct
+ * @param expectedTag the expected value for DTAG
+ * @param gotExpectedTag output a 1 if got the expected tag, else 0
+ * @return 0 for success, else an error string for read past the end of the input
+ */
+char *ndn_BinaryXMLDecoder_peekDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *gotExpectedTag);
/**
* Set the offset into the input, used for the next read.