Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 1 | #include "ccnx-pco.h" |
| 2 | |
| 3 | namespace Ccnx { |
| 4 | |
| 5 | ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len) |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 6 | { |
Zhenkai Zhu | b7aba36 | 2013-01-04 20:58:51 -0800 | [diff] [blame^] | 7 | ccn_indexbuf *comps = ccn_indexbuf_create(); |
| 8 | ccn_parsed_ContentObject pco; |
| 9 | int res = ccn_parse_ContentObject(data, len, &pco, comps); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 10 | if (res < 0) |
| 11 | { |
| 12 | boost::throw_exception(MisformedContentObjectException()); |
| 13 | } |
Zhenkai Zhu | b7aba36 | 2013-01-04 20:58:51 -0800 | [diff] [blame^] | 14 | |
| 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 Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | ParsedContentObject::ParsedContentObject(const Bytes &bytes) |
| 30 | { |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 31 | ParsedContentObject(head(bytes), bytes.size()); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | ParsedContentObject::ParsedContentObject(const ParsedContentObject &other) |
| 35 | { |
Zhenkai Zhu | b7aba36 | 2013-01-04 20:58:51 -0800 | [diff] [blame^] | 36 | m_content = other.m_content; |
| 37 | m_name = other.m_name; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | ParsedContentObject::~ParsedContentObject() |
| 41 | { |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | Bytes |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 45 | ParsedContentObject::content() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 46 | { |
Zhenkai Zhu | b7aba36 | 2013-01-04 20:58:51 -0800 | [diff] [blame^] | 47 | cout << "content() : " << string((const char *)&m_content[0], m_content.size()) << endl; |
| 48 | return m_content; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 51 | Name |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 52 | ParsedContentObject::name() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 53 | { |
Zhenkai Zhu | b7aba36 | 2013-01-04 20:58:51 -0800 | [diff] [blame^] | 54 | cout <<"name() : " << m_name << endl; |
| 55 | return m_name; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } |