blob: 8c2fd3fefb963651678a0d149b0af5c54ae638f7 [file] [log] [blame]
#include "ccnx-pco.h"
namespace Ccnx {
void
ParsedContentObject::init(const unsigned char *data, size_t len)
{
m_comps = ccn_indexbuf_create();
int res = ccn_parse_ContentObject(data, len, &m_pco, m_comps);
if (res < 0)
{
boost::throw_exception(MisformedContentObjectException());
}
readRaw(m_bytes, data, len);
}
ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len)
: m_comps(NULL)
{
init(data, len);
}
ParsedContentObject::ParsedContentObject(const Bytes &bytes)
: m_comps(NULL)
{
init(head(bytes), bytes.size());
}
ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
: m_comps(NULL)
{
init(head(other.m_bytes), other.m_bytes.size());
}
ParsedContentObject::~ParsedContentObject()
{
ccn_indexbuf_destroy(&m_comps);
m_comps = NULL;
}
Bytes
ParsedContentObject::content() const
{
const unsigned char *content;
size_t len;
Bytes bytes;
int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len);
if (res < 0)
{
boost::throw_exception(MisformedContentObjectException());
}
readRaw(bytes, content, len);
return bytes;
}
BytesPtr
ParsedContentObject::contentPtr() const
{
const unsigned char *content;
size_t len;
int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len);
if (res < 0)
{
boost::throw_exception(MisformedContentObjectException());
}
return readRawPtr (content, len);
}
Name
ParsedContentObject::name() const
{
return Name(head(m_bytes), m_comps);
}
}