blob: 1d83b26c5b78711e51f205a4b782ffd7c9df2315 [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)
Zhenkai Zhu43eb2732012-12-28 00:48:26 -08006{
Zhenkai Zhub7aba362013-01-04 20:58:51 -08007 ccn_indexbuf *comps = ccn_indexbuf_create();
8 ccn_parsed_ContentObject pco;
9 int res = ccn_parse_ContentObject(data, len, &pco, comps);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080010 if (res < 0)
11 {
12 boost::throw_exception(MisformedContentObjectException());
13 }
Zhenkai Zhub7aba362013-01-04 20:58:51 -080014
15 const unsigned char *content;
16 size_t length;
17 res = ccn_content_get_value(data, pco.offset[CCN_PCO_E], &pco, &content, &length);
18 if (res < 0)
19 {
20 boost::throw_exception(MisformedContentObjectException());
21 }
22 readRaw(m_content, content, length);
23
24 m_name = Name(data, comps);
25 cout << "in Constructor: name " << m_name << endl;
26 cout << "content : " << string((const char *)&m_content[0], m_content.size()) << endl;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080027}
28
29ParsedContentObject::ParsedContentObject(const Bytes &bytes)
30{
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080031 ParsedContentObject(head(bytes), bytes.size());
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080032}
33
34ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
35{
Zhenkai Zhub7aba362013-01-04 20:58:51 -080036 m_content = other.m_content;
37 m_name = other.m_name;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080038}
39
40ParsedContentObject::~ParsedContentObject()
41{
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080042}
43
44Bytes
Zhenkai Zhubad089c2012-12-28 10:28:27 -080045ParsedContentObject::content() const
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080046{
Zhenkai Zhub7aba362013-01-04 20:58:51 -080047 cout << "content() : " << string((const char *)&m_content[0], m_content.size()) << endl;
48 return m_content;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080049}
50
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080051Name
Zhenkai Zhubad089c2012-12-28 10:28:27 -080052ParsedContentObject::name() const
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080053{
Zhenkai Zhub7aba362013-01-04 20:58:51 -080054 cout <<"name() : " << m_name << endl;
55 return m_name;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080056}
57
58}