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) |
| 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 | |
| 17 | ParsedContentObject::ParsedContentObject(const Bytes &bytes) |
| 18 | { |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 19 | ParsedContentObject(head(bytes), bytes.size()); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | ParsedContentObject::ParsedContentObject(const ParsedContentObject &other) |
| 23 | { |
Zhenkai Zhu | 0d8f5d5 | 2012-12-30 12:54:07 -0800 | [diff] [blame] | 24 | ParsedContentObject(other.m_bytes); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | ParsedContentObject::~ParsedContentObject() |
| 28 | { |
| 29 | ccn_indexbuf_destroy(&m_comps); |
| 30 | m_comps = NULL; |
| 31 | } |
| 32 | |
| 33 | Bytes |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 34 | ParsedContentObject::content() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 35 | { |
| 36 | const unsigned char *content; |
| 37 | size_t len; |
| 38 | Bytes bytes; |
Zhenkai Zhu | 974c5a6 | 2012-12-28 14:15:30 -0800 | [diff] [blame] | 39 | int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 40 | if (res < 0) |
| 41 | { |
| 42 | boost::throw_exception(MisformedContentObjectException()); |
| 43 | } |
| 44 | |
| 45 | readRaw(bytes, content, len); |
| 46 | return bytes; |
| 47 | } |
| 48 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame^] | 49 | Name |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 50 | ParsedContentObject::name() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 51 | { |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame^] | 52 | return Name(head(m_bytes), m_comps); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } |