+StringTag* CollectionReader::readStringTag(bool header) {
+ if (header) {
+ uint16_t unknown = 0;
+ if (!ensureBufferCapacity(2)) {
+ return NULL;
+ }
+ growingBuffer.read(&unknown, 2);
+ }
+ uint8_t tagName = 0;
+ if (!ensureBufferCapacity(1)) {
+ return NULL;
+ }
+ growingBuffer.read(&tagName, 1);
+ GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag name %d.\n", __FILE__, __LINE__, tagName);
+ uint16_t tagLength = 0;
+ if (!ensureBufferCapacity(2)) {
+ return NULL;
+ }
+ growingBuffer.read(&tagLength, 2);
+ GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag length %d.\n", __FILE__, __LINE__, tagLength);
+ char* tagValue = (char*) malloc(tagLength + 1);
+ if (!ensureBufferCapacity(tagLength)) {
+ return NULL;
+ }
+ growingBuffer.read(tagValue, tagLength);
+ tagValue[tagLength] = '\0';
+ StringTag* stringTag = new StringTag(tagName, tagValue);
+ free(tagValue);
+ return stringTag;
+}
+
+BlobTag* CollectionReader::readBlobTag(bool header) {
+ if (header) {
+ uint16_t unknown = 0;
+ if (!ensureBufferCapacity(2)) {
+ return NULL;
+ }
+ growingBuffer.read(&unknown, 2);
+ }
+ uint8_t tagName = 0;
+ if (!ensureBufferCapacity(1)) {
+ return NULL;
+ }
+ growingBuffer.read(&tagName, 1);
+ GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag name %d.\n", __FILE__, __LINE__, tagName);
+ uint32_t tagLength = 0;
+ if (!ensureBufferCapacity(4)) {
+ return NULL;
+ }
+ growingBuffer.read(&tagLength, 4);
+ GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag length %d.\n", __FILE__, __LINE__, tagLength);
+ void* tagValue = (char*) malloc(tagLength);
+ if (!ensureBufferCapacity(tagLength)) {
+ return NULL;
+ }
+ growingBuffer.read(tagValue, tagLength);
+ BlobTag* blobTag = new BlobTag(tagName, tagValue, tagLength);
+ free(tagValue);
+ return blobTag;
+}
+