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 | { |
| 19 | ParsedContentObject((const unsigned char *)bytes[0], bytes.size()); |
| 20 | } |
| 21 | |
| 22 | ParsedContentObject::ParsedContentObject(const ParsedContentObject &other) |
| 23 | { |
| 24 | ParsedContentObject(other.m_bytes); |
| 25 | } |
| 26 | |
| 27 | ParsedContentObject::~ParsedContentObject() |
| 28 | { |
| 29 | ccn_indexbuf_destroy(&m_comps); |
| 30 | m_comps = NULL; |
| 31 | } |
| 32 | |
| 33 | Bytes |
| 34 | ParsedContentObject::content() |
| 35 | { |
| 36 | const unsigned char *content; |
| 37 | size_t len; |
| 38 | Bytes bytes; |
| 39 | int res = ccn_content_get_value((const unsigned char *)m_bytes[0], m_pco.offset[CCN_PCO_E], &m_pco, &content, &len); |
| 40 | if (res < 0) |
| 41 | { |
| 42 | boost::throw_exception(MisformedContentObjectException()); |
| 43 | } |
| 44 | |
| 45 | readRaw(bytes, content, len); |
| 46 | return bytes; |
| 47 | } |
| 48 | |
| 49 | string |
| 50 | ParsedContentObject::name() |
| 51 | { |
| 52 | return CcnxWrapper::extractName((const unsigned char *)m_bytes[0], m_comps); |
| 53 | } |
| 54 | |
| 55 | } |