Checkpoint in further separating action-log from sync-log
diff --git a/ccnx/ccnx-name.cpp b/ccnx/ccnx-name.cpp
index 848019a..cf6a475 100644
--- a/ccnx/ccnx-name.cpp
+++ b/ccnx/ccnx-name.cpp
@@ -57,6 +57,14 @@
init(other.m_buf);
}
+CcnxCharbuf::CcnxCharbuf(const void *buf, size_t length)
+{
+ m_buf = ccn_charbuf_create ();
+ ccn_charbuf_reserve (m_buf, length);
+ memcpy (m_buf->buf, buf, length);
+ m_buf->length = length;
+}
+
CcnxCharbuf::~CcnxCharbuf()
{
ccn_charbuf_destroy(&m_buf);
@@ -126,6 +134,41 @@
ccn_indexbuf_destroy(&idx);
}
+Name::Name (const CcnxCharbuf &buf)
+{
+ ccn_indexbuf *idx = ccn_indexbuf_create();
+ ccn_name_split (buf.getBuf (), idx);
+
+ const unsigned char *compPtr = NULL;
+ size_t size = 0;
+ int i = 0;
+ while (ccn_name_comp_get(buf.getBuf ()->buf, idx, i, &compPtr, &size) == 0)
+ {
+ Bytes comp;
+ readRaw (comp, compPtr, size);
+ m_comps.push_back(comp);
+ i++;
+ }
+ ccn_indexbuf_destroy(&idx);
+}
+
+Name::Name (const ccn_charbuf *buf)
+{
+ ccn_indexbuf *idx = ccn_indexbuf_create();
+ ccn_name_split (buf, idx);
+
+ const unsigned char *compPtr = NULL;
+ size_t size = 0;
+ int i = 0;
+ while (ccn_name_comp_get(buf->buf, idx, i, &compPtr, &size) == 0)
+ {
+ Bytes comp;
+ readRaw (comp, compPtr, size);
+ m_comps.push_back(comp);
+ i++;
+ }
+ ccn_indexbuf_destroy(&idx);
+}
Name &
Name::operator=(const Name &other)
diff --git a/ccnx/ccnx-name.h b/ccnx/ccnx-name.h
index 92c3054..ff93a7d 100644
--- a/ccnx/ccnx-name.h
+++ b/ccnx/ccnx-name.h
@@ -37,11 +37,16 @@
CcnxCharbuf();
CcnxCharbuf(ccn_charbuf *buf);
CcnxCharbuf(const CcnxCharbuf &other);
+ CcnxCharbuf(const void *buf, size_t length);
~CcnxCharbuf();
// expose internal data structure, use with caution!!
ccn_charbuf *
getBuf() { return m_buf; }
+
+ const ccn_charbuf *
+ getBuf() const { return m_buf; }
+
static CcnxCharbufPtr Null;
const unsigned char *
@@ -72,6 +77,8 @@
Name(const Name &other);
Name(const unsigned char *data, const ccn_indexbuf *comps);
Name (const unsigned char *buf, const size_t length);
+ Name (const CcnxCharbuf &buf);
+ Name (const ccn_charbuf *buf);
virtual ~Name() {}
CcnxCharbufPtr
@@ -141,7 +148,7 @@
friend Name
operator+(const Name &n1, const Name &n2);
-protected:
+private:
vector<Bytes> m_comps;
};