decode static method

PeerState? decode(
  1. Unpacker u
)

Implementation

static PeerState? decode(Unpacker u) {
  try {
    switch (u.unpackString()) {
      case "Known": return PeerStateKnown();
      case "Connecting": return PeerStateConnecting();
      case "Handshaking": return PeerStateHandshaking();
      case null: return null;
      default: throw DecodeError();
    }
  } on FormatException {
    if (u.unpackMapLength() != 1) throw DecodeError();
    switch (u.unpackString()) {
      case "Active":
        if (u.unpackListLength() != 2) throw DecodeError();
        return PeerStateActive(
          id: (PublicRuntimeId.decode(u))!,
          since: (_decodeDateTime(u))!,
        );
      case null: return null;
      default: throw DecodeError();
    }
  }
}