fromProtobufBytes static method

PeerRecord fromProtobufBytes(
  1. Uint8List payload
)

UnmarshalRecord parses a PeerRecord from a byte slice. This method is called automatically when consuming a record.Envelope whose PayloadType indicates that it contains a PeerRecord. Unmarshal a record payload into a concrete PeerRecord instance

Implementation

// PeerRecord unmarshalRecord(Uint8List bytes) {
//   try {
//     final msg = pb.PeerRecord.fromBuffer(bytes);
//     return
//     this.peerId = msg.peerId;
//     this.addrs = msg.addresses;
//     this.seq = msg.seq;
//
//     return PeerRecord.fromProtobuf(msg);
//   } catch (e) {
//     throw FormatException('Failed to unmarshal PeerRecord: $e');
//   }
// }

/// Unmarshal a record payload into a concrete PeerRecord instance
///
static PeerRecord fromProtobufBytes(Uint8List payload) {
  try {
    final msg = pb.PeerRecord.fromBuffer(payload);
    return PeerRecord(
        peerId: PeerId.fromBytes(Uint8List.fromList(msg.peerId)),
        addrs: _addrsFromProtobuf(msg.addresses),
        seq: msg.seq.toInt());
  } catch (e) {
    throw FormatException('Failed to unmarshal PeerRecord: $e');
  }
}