blob: f592f53331cf87505fea92e4d15b10a1f7ced386 [file] [log] [blame]
Zhenkai Zhu43eb2732012-12-28 00:48:26 -08001#include "ccnx-pco.h"
2
3namespace Ccnx {
4
5ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len)
6 : m_comps(NULL)
7{
8 m_comps = ccn_indexbuf_create();
9 int res = ccn_parse_ContentObject(data, len, &m_pco, m_comps);
10 if (res < 0)
11 {
12 boost::throw_exception(MisformedContentObjectException());
13 }
14 readRaw(m_bytes, data, len);
15}
16
17ParsedContentObject::ParsedContentObject(const Bytes &bytes)
18{
19 ParsedContentObject((const unsigned char *)bytes[0], bytes.size());
20}
21
22ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
23{
24 ParsedContentObject(other.m_bytes);
25}
26
27ParsedContentObject::~ParsedContentObject()
28{
29 ccn_indexbuf_destroy(&m_comps);
30 m_comps = NULL;
31}
32
33Bytes
34ParsedContentObject::content()
35{
36 const unsigned char *content;
37 size_t len;
38 Bytes bytes;
39 int res = ccn_content_get_value((const unsigned char *)m_bytes[0], m_pco.offset[CCN_PCO_E], &m_pco, &content, &len);
40 if (res < 0)
41 {
42 boost::throw_exception(MisformedContentObjectException());
43 }
44
45 readRaw(bytes, content, len);
46 return bytes;
47}
48
49string
50ParsedContentObject::name()
51{
52 return CcnxWrapper::extractName((const unsigned char *)m_bytes[0], m_comps);
53}
54
55}