| 79 | } |
| 80 | |
| 81 | bool |
| 82 | DocNode::unpack(const char *packed_data, int packed_data_len, int &node_len) |
| 83 | { |
| 84 | const char *packed_data_start = packed_data; |
| 85 | |
| 86 | if (!packed_data || (packed_data_len < static_cast<int>((sizeof(char) + sizeof(int32_t))))) { |
| 87 | TSError("[%s] Invalid arguments (%p, %d)", __FUNCTION__, packed_data, packed_data_len); |
| 88 | return false; |
| 89 | } |
| 90 | if (*packed_data != DOCNODE_VERSION) { |
| 91 | TSError("[%s] Version %d not in supported set (%d)", __FUNCTION__, static_cast<int>(*packed_data), |
| 92 | static_cast<int>(DOCNODE_VERSION)); |
| 93 | return false; |
| 94 | } |
| 95 | ++packed_data; |
| 96 | |
| 97 | int32_t node_size; |
| 98 | unpackItem(packed_data, node_size); |
| 99 | if (node_size > packed_data_len) { |
| 100 | TSError("[%s] Data size (%d) not sufficient to hold node of size %d", __FUNCTION__, packed_data_len, node_size); |
| 101 | return false; |
| 102 | } |
| 103 | node_len = node_size; |
| 104 | |
| 105 | unpackItem(packed_data, type); |
| 106 | |
| 107 | unpackString(packed_data, data, data_len); |
| 108 | |
| 109 | int32_t n_elements; |
| 110 | unpackItem(packed_data, n_elements); |
| 111 | Attribute attr; |
| 112 | attr_list.clear(); |
| 113 | for (int i = 0; i < n_elements; ++i) { |
| 114 | unpackString(packed_data, attr.name, attr.name_len); |
| 115 | unpackString(packed_data, attr.value, attr.value_len); |
| 116 | attr_list.push_back(attr); |
| 117 | } |
| 118 | |
| 119 | if (!child_nodes.unpack(packed_data, packed_data_len - (packed_data - packed_data_start))) { |
| 120 | TSError("[%s] Could not unpack child nodes", __FUNCTION__); |
| 121 | return false; |
| 122 | } |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | void |
| 127 | DocNodeList::packToBuffer(string &buffer) const |
no test coverage detected