public override void FromBytes(byte[] bytes) { Guard.NotNullOrEmpty(nameof(bytes), bytes); Guard.Same($"{nameof(bytes)}.{nameof(bytes.Length)}", 2, bytes.Length); Ver = new VerField(); Ver.FromByte(bytes[0]); Method = new MethodField(); Method.FromByte(bytes[1]); }
public override void FromBytes(byte[] bytes) { Guard.NotNullOrEmpty(nameof(bytes), bytes); Guard.MinimumAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 6); Ver = new VerField(); Ver.FromByte(bytes[0]); Rep = new RepField(); Rep.FromByte(bytes[1]); Rsv = new RsvField(); Rsv.FromByte(bytes[2]); Atyp = new AtypField(); Atyp.FromByte(bytes[3]); BndAddr = new AddrField(); BndAddr.FromBytes(bytes[4..^ 2]);
public override void FromBytes(byte[] bytes) { Guard.NotNullOrEmpty(nameof(bytes), bytes); Guard.InRangeAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 3, 257); Ver = new VerField(); Ver.FromByte(bytes[0]); NMethods = new NMethodsField(); NMethods.FromByte(bytes[1]); if (NMethods.Value != bytes.Length - 2) { throw new FormatException($"{nameof(NMethods)}.{nameof(NMethods.Value)} must be {nameof(bytes)}.{nameof(bytes.Length)} - 2` = {bytes.Length - 2}. Actual: {NMethods.Value}."); } Methods = new MethodsField(); Methods.FromBytes(bytes.Skip(2).ToArray()); }
public override void FromBytes(byte[] bytes) { Guard.NotNullOrEmpty(nameof(bytes), bytes); Guard.MinimumAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 6); Ver = new VerField(); Ver.FromByte(bytes[0]); Cmd = new CmdField(); Cmd.FromByte(bytes[1]); Rsv = new RsvField(); Rsv.FromByte(bytes[2]); Atyp = new AtypField(); Atyp.FromByte(bytes[3]); DstAddr = new AddrField(); DstAddr.FromBytes(bytes.Skip(4).Take(bytes.Length - 4 - 2).ToArray()); DstPort = new PortField(); DstPort.FromBytes(bytes.Skip(bytes.Length - 2).ToArray()); }