Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 1 | #include "ccnx-pco.h" |
| 2 | |
| 3 | namespace Ccnx { |
| 4 | |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 5 | void |
| 6 | ParsedContentObject::init(const unsigned char *data, size_t len) |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 7 | { |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 8 | m_comps = ccn_indexbuf_create(); |
| 9 | int res = ccn_parse_ContentObject(data, len, &m_pco, m_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 | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 14 | readRaw(m_bytes, data, len); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 15 | } |
| 16 | |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 17 | ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len) |
| 18 | : m_comps(NULL) |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 19 | { |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 20 | init(data, len); |
| 21 | } |
| 22 | |
| 23 | ParsedContentObject::ParsedContentObject(const Bytes &bytes) |
| 24 | : m_comps(NULL) |
| 25 | { |
| 26 | init(head(bytes), bytes.size()); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | ParsedContentObject::ParsedContentObject(const ParsedContentObject &other) |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 30 | : m_comps(NULL) |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 31 | { |
Zhenkai Zhu | 9f2ef6f | 2013-01-04 21:46:08 -0800 | [diff] [blame] | 32 | init(head(other.m_bytes), other.m_bytes.size()); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | ParsedContentObject::~ParsedContentObject() |
| 36 | { |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 37 | ccn_indexbuf_destroy(&m_comps); |
| 38 | m_comps = NULL; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | Bytes |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 42 | ParsedContentObject::content() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 43 | { |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 44 | const unsigned char *content; |
| 45 | size_t len; |
| 46 | Bytes bytes; |
| 47 | int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len); |
| 48 | if (res < 0) |
| 49 | { |
| 50 | boost::throw_exception(MisformedContentObjectException()); |
| 51 | } |
| 52 | |
| 53 | readRaw(bytes, content, len); |
| 54 | return bytes; |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame^] | 57 | BytesPtr |
| 58 | ParsedContentObject::contentPtr() const |
| 59 | { |
| 60 | const unsigned char *content; |
| 61 | size_t len; |
| 62 | int res = ccn_content_get_value(head(m_bytes), m_pco.offset[CCN_PCO_E], &m_pco, &content, &len); |
| 63 | if (res < 0) |
| 64 | { |
| 65 | boost::throw_exception(MisformedContentObjectException()); |
| 66 | } |
| 67 | |
| 68 | return readRawPtr (content, len); |
| 69 | } |
| 70 | |
Zhenkai Zhu | cb2d0dd | 2013-01-03 14:10:48 -0800 | [diff] [blame] | 71 | Name |
Zhenkai Zhu | bad089c | 2012-12-28 10:28:27 -0800 | [diff] [blame] | 72 | ParsedContentObject::name() const |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 73 | { |
Zhenkai Zhu | 9061180 | 2013-01-04 21:30:24 -0800 | [diff] [blame] | 74 | return Name(head(m_bytes), m_comps); |
Zhenkai Zhu | 43eb273 | 2012-12-28 00:48:26 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | } |