public byte[] GetBytes() { ushort length = (ushort)fragment.Length; byte[] result = new byte[length + 5]; int offset = 0; System.Buffer.BlockCopy(BitConverter.GetBytes((char)(type)), 0, result, offset, 1); offset += 1; System.Buffer.BlockCopy(version.GetBytes(), 0, result, offset, version.Length); offset += version.Length; byte[] len = BitConverter.GetBytes(length); if (BitConverter.IsLittleEndian) { Array.Reverse(len); } System.Buffer.BlockCopy(len, 0, result, offset, len.Length); offset += len.Length; System.Buffer.BlockCopy(fragment, 0, result, offset, fragment.Length); offset += fragment.Length; return(result); }
/* utility methods */ public byte[] GetBytes() { byte[] result = new byte[this.GetLength()]; int offset = 0; System.Buffer.BlockCopy(version.GetBytes(), 0, result, offset, version.Length); offset += version.Length; System.Buffer.BlockCopy(random.GetBytes(), 0, result, offset, RandomUnit.Length); offset += RandomUnit.Length; System.Buffer.BlockCopy(sid.ToBytes(), 0, result, offset, sid.Length == 0 ? 1 : 0); offset += sid.Length == 0 ? 1 : 0; byte[] length = BitConverter.GetBytes((ushort)(2 * CipherSuites.Length)); if (BitConverter.IsLittleEndian) { Array.Reverse(length); } System.Buffer.BlockCopy(length, 0, result, offset, 2); offset += 2; System.Buffer.BlockCopy(CipherSuites.GetSupportedSuitesInBytes(), 0, result, offset, (CipherSuites.Length * 2)); offset += CipherSuites.Length * 2; System.Buffer.BlockCopy(CompressionList.ToBytes(), 0, result, offset, 1 + CompressionList.Length); offset += 1 + CompressionList.Length; return(result); }
public byte[] ToBytes(RecordLayer.Record record) { byte[] fragment = record.Payload; if (fragment == null) { throw new ArgumentNullException(); } ushort length = (ushort)fragment.Length; byte[] result = new byte[length + 5]; int offset = 0; System.Buffer.BlockCopy(BitConverter.GetBytes((char)record.Type), 0, result, offset, 1); offset += 1; ProtocolVersion version = record.Version; System.Buffer.BlockCopy(version.GetBytes(), 0, result, offset, version.Length); offset += version.Length; byte[] len = BitConverter.GetBytes(length); if (BitConverter.IsLittleEndian) { Array.Reverse(len); } System.Buffer.BlockCopy(len, 0, result, offset, len.Length); offset += len.Length; System.Buffer.BlockCopy(fragment, 0, result, offset, fragment.Length); offset += fragment.Length; return(result); }
public byte[] GetBytes() { byte[] result = new byte[48]; ProtocolVersion version = new ProtocolVersion(); System.Buffer.BlockCopy(version.GetBytes(), 0, result, 0, version.Length); System.Buffer.BlockCopy(m_RandomBytes, 0, result, 2, m_RandomBytes.Length); return(result); }
protected override byte[] GetPayload() { return(ProtocolVersion.GetBytes() .Concat(Services) .Concat(Timestamp.ToUnixTimeSeconds()) .Concat(To) .Concat(From) .Concat(Nonce) .Concat(UserAgent) .Concat(StartHeight) .Concat(Relay) .ToArray()); }