public static byte[] EncodeNetworkAddressKey(NetworkAddressKey networkAddressKey) { using (var stream = new MemoryStream()) { EncodeNetworkAddressKey(stream, networkAddressKey); return(stream.ToArray()); } }
public static void EncodeNetworkAddressKey(Stream stream, NetworkAddressKey networkAddressKey) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, leaveOpen: true)) { writer.WriteVarBytes(networkAddressKey.IPv6Address.ToArray()); writer.Write(networkAddressKey.Port); } }
public bool TryGetValue(NetworkAddressKey networkAddressKey, out NetworkAddressWithTime networkAddressWithTime) { byte[] networkAddressWithTimeBytes; if (this.dict.TryGetValue(EncodeKey(networkAddressKey), out networkAddressWithTimeBytes)) { networkAddressWithTime = DecodeValue(networkAddressWithTimeBytes); return(true); } else { networkAddressWithTime = default(NetworkAddressWithTime); return(false); } }
public NetworkAddressWithTime this[NetworkAddressKey networkAddressKey] { get { NetworkAddressWithTime networkAddressWithTime; if (this.TryGetValue(networkAddressKey, out networkAddressWithTime)) { return(networkAddressWithTime); } throw new KeyNotFoundException(); } set { this.dict[EncodeKey(networkAddressKey).ToArray()] = EncodeValue(value); } }
public bool TryAdd(NetworkAddressKey networkAddressKey, NetworkAddressWithTime networkAddressWithTime) { if (!this.ContainsKey(networkAddressKey)) { try { this.dict.Add(EncodeKey(networkAddressKey), EncodeValue(networkAddressWithTime)); return(true); } catch (ArgumentException) { return(false); } } else { return(false); } }
public bool TryRemove(NetworkAddressKey networkAddressKey) { return(this.dict.Remove(EncodeKey(networkAddressKey))); }
public bool ContainsKey(NetworkAddressKey networkAddressKey) { return(this.dict.ContainsKey(EncodeKey(networkAddressKey))); }
private static byte[] EncodeKey(NetworkAddressKey networkAddressKey) { return(NodeEncoder.EncodeNetworkAddressKey(networkAddressKey)); }
public static byte[] EncodeNetworkAddressKey(NetworkAddressKey networkAddressKey) { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { EncodeNetworkAddressKey(writer, networkAddressKey); return stream.ToArray(); } }
public static void EncodeNetworkAddressKey(BinaryWriter writer, NetworkAddressKey networkAddressKey) { writer.WriteVarBytes(networkAddressKey.IPv6Address.ToArray()); writer.Write(networkAddressKey.Port); }