add method to read hash tag
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Jul 2008 10:59:19 +0000 (12:59 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Jul 2008 10:59:19 +0000 (12:59 +0200)
CollectionReader.cpp
CollectionReader.h

index ffbb89c..00427ff 100644 (file)
@@ -83,6 +83,21 @@ BlobTag* CollectionReader::readBlobTag(bool header) {
        return blobTag;
 }
 
+HashTag* CollectionReader::readHashTag() {
+       if (!ensureBufferCapacity(1)) {
+               return NULL;
+       }
+       uint8_t tagId = 0;
+       growingBuffer.read(&tagId, 1);
+       GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] read tag id %d.\n", __FILE__, __LINE__, tagId);
+       if (!ensureBufferCapacity(16)) {
+               return NULL;
+       }
+       char hash[16];
+       growingBuffer.read(hash, 16);
+       return new HashTag(tagId, hash);
+}
+
 ED2KLink* CollectionReader::getNextLink() {
        if (readerInput->isEOF() && !growingBuffer.getRemaining()) {
                GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] readInput EOF reached.\n", __FILE__, __LINE__);
index 770c2a8..023b226 100644 (file)
@@ -10,6 +10,7 @@
 #include "GrowingBuffer.h"
 #include "StringTag.h"
 #include "BlobTag.h"
+#include "HashTag.h"
 
 class CollectionReader {
 
@@ -25,8 +26,9 @@ private:
        bool ensureBufferCapacity(size_t byteCount);
        void readMoreBytes();
 
-       BlobTag* readBlobTag(bool hader);
-       StringTag* readStringTag(bool header);
+       BlobTag* readBlobTag(bool header = false);
+       StringTag* readStringTag(bool header = false);
+       HashTag* readHashTag();
 
 private:
        ReaderInput* readerInput;