blob: 1c2489101e23c1ffd1a187dd13ce39f0da1eb048 [file] [log] [blame]
#include "ccnx-pco.h"
namespace Ccnx {
ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len)
: m_comps(NULL)
{
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 Bytes &bytes)
{
ParsedContentObject(head(bytes), bytes.size());
}
ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
{
ParsedContentObject(other.m_bytes);
}
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;
}
string
ParsedContentObject::name() const
{
return CcnxWrapper::extractName(head(m_bytes), m_comps);
}
}