public void Write <T>(T val) { lock (rbsWriteLock) { switch (val) { case int number: numberWriter.Write(number, BitsPerInt); break; case bool flag: rawBitStream.Write(flag); break; case Guid uuid: uuidsWriter.Write(uuid); break; case string str: var cache = Encoding.UTF8.GetBytes(str); bytesWriter.Write(cache); break; default: throw new NotSupportedException( $"Not supported type {typeof(T)}"); } } }
public void Write(string address) { var bitStream = GetParent(); var ip = ParseIpAddress(address); var str = Utils.CutBytes(Encoding.UTF8.GetBytes(address)); var ipBytes = ip?.GetAddressBytes(); if (ipBytes != null && ipBytes.Length < str.Length) { bitStream.Write(true); var isIpv6 = ip.AddressFamily == AddressFamily.InterNetworkV6; bitStream.Write(isIpv6); bytesWriter.Write(ipBytes, ipBytes.Length); } else { bitStream.Write(false); bytesWriter.Write(str); } }
public void Write(Guid uuid) => bytesWriter.Write(uuid.ToByteArray(), BytesPerUuid);