static*/
| 71 | } |
| 72 | |
| 73 | /*static*/ bool microStore::Codec<DestinationEntry>::decode(const std::vector<uint8_t>& data, DestinationEntry& entry) |
| 74 | { |
| 75 | if (data.empty()) return false; |
| 76 | |
| 77 | MsgPack::Unpacker u; |
| 78 | u.feed(data.data(), data.size()); |
| 79 | |
| 80 | if (!u.isArray()) return false; |
| 81 | const size_t n = u.unpackArraySize(); |
| 82 | if (n < 7) return false; |
| 83 | |
| 84 | // timestamp |
| 85 | if (!u.deserialize(entry._timestamp)) return false; |
| 86 | |
| 87 | // hops |
| 88 | if (!u.deserialize(entry._hops)) return false; |
| 89 | |
| 90 | // expires |
| 91 | if (!u.deserialize(entry._expires)) return false; |
| 92 | |
| 93 | // received_from |
| 94 | { |
| 95 | MsgPack::bin_t<uint8_t> b; |
| 96 | if (!u.deserialize(b)) return false; |
| 97 | entry._received_from = Bytes(b.data(), b.size()); |
| 98 | } |
| 99 | |
| 100 | // random_blobs |
| 101 | { |
| 102 | if (!u.isArray()) return false; |
| 103 | const size_t blob_n = u.unpackArraySize(); |
| 104 | entry._random_blobs.clear(); |
| 105 | entry._random_blobs.reserve(blob_n); |
| 106 | for (size_t i = 0; i < blob_n; i++) { |
| 107 | MsgPack::bin_t<uint8_t> b; |
| 108 | if (!u.deserialize(b)) return false; |
| 109 | entry._random_blobs.push_back(Bytes(b.data(), b.size())); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // receiving_interface (rebind to live Interface by hash) |
| 114 | { |
| 115 | MsgPack::bin_t<uint8_t> b; |
| 116 | if (!u.deserialize(b)) return false; |
| 117 | Bytes interface_hash(b.data(), b.size()); |
| 118 | entry._receiving_interface = Transport::find_interface_from_hash(interface_hash); |
| 119 | if (!entry._receiving_interface) { |
| 120 | WARNINGF("Path Interface %s not found", interface_hash.toHex().c_str()); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // announce_packet |
| 125 | { |
| 126 | MsgPack::bin_t<uint8_t> b; |
| 127 | if (!u.deserialize(b)) return false; |
| 128 | Bytes packet_data(b.data(), b.size()); |
| 129 | if (packet_data.size() > 0) { |
| 130 | entry._announce_packet = Packet(packet_data); |