blob: dce3bcb3a4b887462787f56debcd255c637f0014 [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{
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080019 ParsedContentObject(head(bytes), bytes.size());
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080020}
21
22ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
23{
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080024 ParsedContentObject(other.m_bytes);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080025}
26
27ParsedContentObject::~ParsedContentObject()
28{
29 ccn_indexbuf_destroy(&m_comps);
30 m_comps = NULL;
31}
32
33Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080034ParsedContentObject::content() const
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080035{
36 const unsigned char *content;
37 size_t len;
38 Bytes bytes;
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080039 int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080040 if (res < 0)
41 {
42 boost::throw_exception(MisformedContentObjectException());
43 }
44
45 readRaw(bytes, content, len);
46 return bytes;
47}
48
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080049Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080050ParsedContentObject::name() const
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080051{
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080052 return Name(head(m_bytes), m_comps);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080053}
54
55}