public byte[] GetBytes() { byte[] r = new byte[16]; fixed(byte *rbyte = r) fixed(byte *pbyte = bytes) { Extractor.CopyBlock(rbyte, pbyte, 16); } return(r); }
/// <summary> /// The ComputeHashAsync. /// </summary> /// <param name="stream">The stream<see cref="Stream"/>.</param> /// <param name="bufferSize">The bufferSize<see cref="int"/>.</param> /// <param name="seed">The seed<see cref="uint"/>.</param> /// <param name="cancellationToken">The cancellationToken<see cref="CancellationToken"/>.</param> /// <returns>The <see cref="ValueTask{uint}"/>.</returns> public static async ValueTask <uint> ComputeHashAsync(Stream stream, int bufferSize, uint seed, CancellationToken cancellationToken) { Debug.Assert(stream != null); Debug.Assert(bufferSize > 16); byte[] buffer = ArrayPool <byte> .Shared.Rent(bufferSize + 16); int readBytes; int offset = 0; long length = 0; uint v1 = seed + p1 + p2; uint v2 = seed + p2; uint v3 = seed + 0; uint v4 = seed - p1; try { while ((readBytes = await stream.ReadAsync(buffer, offset, bufferSize, cancellationToken).ConfigureAwait(false)) > 0) { if (cancellationToken.IsCancellationRequested) { return(await Task.FromCanceled <uint>(cancellationToken)); } length = length + readBytes; offset = offset + readBytes; if (offset < 16) { continue; } int r = offset % 16; int l = offset - r; UnsafeAlign(buffer, l, ref v1, ref v2, ref v3, ref v4); Extractor.CopyBlock(buffer, 0, buffer, l, r); offset = r; } uint h32 = UnsafeFinal(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); return(h32); } finally { ArrayPool <byte> .Shared.Return(buffer); } }
public Ussc(byte[] b) { if (b != null) { int l = b.Length; if (l > 16) l = 16; fixed(byte *dbp = bytes) fixed(byte *sbp = b) { Extractor.CopyBlock(dbp, sbp, l); } } }
public Usid(byte[] b) { if (b != null) { int l = b.Length; if (l > 8) { l = 8; fixed(byte *dbp = bytes) fixed(byte *sbp = b) { Extractor.CopyBlock(dbp, sbp, l); } } }
public static uint ComputeHash(Stream stream, int bufferSize = 4096, uint seed = 0) { Debug.Assert(stream != null); Debug.Assert(bufferSize > 16); byte[] buffer = ArrayPool <byte> .Shared.Rent(bufferSize + 16); int readBytes; int offset = 0; long length = 0; uint v1 = seed + p1 + p2; uint v2 = seed + p2; uint v3 = seed + 0; uint v4 = seed - p1; try { while ((readBytes = stream.Read(buffer, offset, bufferSize)) > 0) { length = length + readBytes; offset = offset + readBytes; if (offset < 16) { continue; } int r = offset % 16; int l = offset - r; UnsafeAlign(buffer, l, ref v1, ref v2, ref v3, ref v4); Extractor.CopyBlock(buffer, 0, buffer, l, (uint)r); offset = r; } uint h32 = UnsafeFinal(buffer, offset, ref v1, ref v2, ref v3, ref v4, length, seed); return(h32); } finally { ArrayPool <byte> .Shared.Return(buffer); } }
public unsafe static int ToInt32(this Byte[] bytes) { int v = 0; uint l = (uint)bytes.Length; fixed(byte *pbyte = bytes) { if (l < 4) { byte *a = stackalloc byte[4]; Extractor.CopyBlock(a, pbyte, l); v = *((int *)a); } v = *((int *)pbyte); } return(v); }
public unsafe static long ToInt64(this Byte[] bytes) { long v = 0; uint l = (uint)bytes.Length; fixed(byte *pbyte = bytes) { if (l < 8) { byte *a = stackalloc byte[8]; Extractor.CopyBlock(a, pbyte, l); v = *((long *)a); } v = *((long *)pbyte); } return(v); }
public MarkupType ReceiveBytes(byte[] buffer, long received) { MarkupType noiseKind = MarkupType.None; lock (binReceive) { int offset = 0, length = (int)received; bool inprogress = false; if (SerialPacketSize == 0) { SerialPacketSize = BitConverter.ToInt64(buffer, 4); DeserialPacketId = BitConverter.ToInt32(buffer, 12); binReceive = new byte[SerialPacketSize]; GCHandle gc = GCHandle.Alloc(binReceive, GCHandleType.Pinned); binReceivePtr = GCHandle.ToIntPtr(gc); offset = SerialPacketOffset; length -= SerialPacketOffset; } if (SerialPacketSize > 0) { inprogress = true; } SerialPacketSize -= length; if (SerialPacketSize < 1) { long endPosition = received; noiseKind = buffer.SeekMarkup(out endPosition, SeekDirection.Backward); } int destid = (binReceive.Length - ((int)SerialPacketSize + length)); if (inprogress) { fixed(byte *msgbuff = buffer) { Extractor.CopyBlock(GCHandle.FromIntPtr(binReceivePtr).AddrOfPinnedObject().ToPointer(), (ulong)destid, msgbuff, (ulong)offset, (ulong)length); // Extractor.CopyBlock(GCHandle.FromIntPtr(binReceivePtr).AddrOfPinnedObject() + destid, new IntPtr(msgbuff) + offset, (ulong)length); } } } return(noiseKind); }
public unsafe MarkupType SyncMessage(int received) { MarkupType noiseKind = MarkupType.None; lock (binReceive) { int offset = 0, length = received; bool inprogress = false; if (SerialPacketSize == 0) { SerialPacketSize = *((int *)(messageBufferAddress + 4).ToPointer()); DeserialPacketId = *((int *)(messageBufferAddress + 12).ToPointer()); binReceive = new byte[SerialPacketSize]; GCHandle gc = GCHandle.Alloc(binReceive, GCHandleType.Pinned); binReceiveHandler = GCHandle.ToIntPtr(gc); binReceiveAddress = gc.AddrOfPinnedObject(); offset = SerialPacketOffset; length -= SerialPacketOffset; } if (SerialPacketSize > 0) { inprogress = true; } SerialPacketSize -= length; if (SerialPacketSize < 1) { long endPosition = length; noiseKind = MessageBuffer.SeekMarkup(out endPosition, SeekDirection.Backward); } int destid = (int)(binReceive.Length - (SerialPacketSize + length)); if (inprogress) { Extractor.CopyBlock(binReceiveAddress, destid, messageBufferAddress, offset, length); } } return(noiseKind); }
public byte[] this[int offset] { get { if (offset != 0) { int l = 16 - offset; byte[] r = new byte[l]; fixed(byte *pbyte = bytes) fixed(byte *rbyte = r) { Extractor.CopyBlock(rbyte, pbyte + offset, l); } return(r); } return(null); } set { int l = value.Length; if (offset > 0 && l < 16) { int count = 16 - offset; if (l < count) { count = l; fixed(byte *pbyte = bytes) fixed(byte *rbyte = value) { Extractor.CopyBlock(pbyte, rbyte, offset, count); } } else { fixed(byte *pbyte = bytes) fixed(byte *rbyte = value) { Extractor.CopyBlock(pbyte, rbyte, 16); } } } }
public byte[] this[int offset, int length] { get { if (offset < 16) { if ((16 - offset) > length) { length = 16 - offset; } byte[] r = new byte[length]; fixed(byte *pbyte = bytes) fixed(byte *rbyte = r) { Extractor.CopyBlock(rbyte, pbyte + offset, length); } return(r); } return(null); } set { if (offset < 16) { if ((16 - offset) > length) { length = 16 - offset; } if (value.Length < length) length = value.Length; fixed(byte *rbyte = value) fixed(byte *pbyte = bytes) { Extractor.CopyBlock(pbyte, rbyte, offset, length); } } } }
public byte[] this[int offset] { get { if (offset > 0 && offset < 8) { int l = (8 - offset); byte[] r = new byte[l]; fixed(byte *pbyte = bytes) fixed(byte *rbyte = r) Extractor.CopyBlock(rbyte, pbyte + offset, l); return(r); } return(GetBytes()); } set { int l = value.Length; if (offset > 0 || l < 8) { int count = 8 - offset; if (l < count) count = l; fixed(byte *pbyte = bytes) fixed(byte *rbyte = value) { Extractor.CopyBlock(pbyte, rbyte, offset, l); } } else { fixed(byte *v = value) fixed(byte *b = bytes) * (ulong *)b = *(ulong *)v; } } }
public byte[] this[int offset] { get { if (offset != 0) { uint l = (uint)(8 - offset); byte[] r = new byte[l]; fixed(byte *pbyte = &NotSureBytes[offset]) fixed(byte *rbyte = r) Extractor.CopyBlock(rbyte, pbyte, l); return(r); } return(NotSureBytes); } set { int l = value.Length; if (offset != 0 || l < 8) { int count = 8 - offset; if (l < count) { count = l; } value.CopyBlock(SureBytes, (uint)offset, (uint)count); } else { fixed(byte *v = value) fixed(byte *b = SureBytes) * (long *)b = *(long *)v; } } }
public static unsafe void CopyBlock(this byte[] src, byte[] dest, ulong count) { Extractor.CopyBlock(src, dest, 0, count); }
protected virtual void Write(byte *source, long length, long position = 0, Type t = null, int timeout = 1000) { Extractor.CopyBlock(BufferStartPtr, (ulong)position, source, 0, (ulong)length); }
public void CopyTo(IStock destination, uint length, int startIndex = 0) { Extractor.CopyBlock(destination.GetStockPtr() + startIndex, this.GetStockPtr(), length); }
protected virtual void Read(byte *destination, long length, long position = 0, Type t = null, int timeout = 1000) { Extractor.CopyBlock(destination, 0, BufferStartPtr, (ulong)position, (ulong)length); }
public void CopyTo(IStock destination, uint length, int position = 0) { Extractor.CopyBlock(destination.GetStockPtr() + position, this.GetStockPtr(), length); }
public static unsafe void CopyBlock(this byte[] src, byte[] dest, uint offset, uint count) { Extractor.CopyBlock(src, dest, offset, count); }
public static unsafe void CopyBlock(this IntPtr src, IntPtr dest, ulong count) { Extractor.CopyBlock(dest, 0, src, 0, count); }
public static unsafe void CopyBlock(this IntPtr src, IntPtr dest, uint offset, uint count) { Extractor.CopyBlock(dest, offset, src, 0, count); }
public static unsafe void CopyBlock(this IntPtr src, ulong srcOffset, IntPtr dest, ulong destOffset, ulong count) { Extractor.CopyBlock(dest, destOffset, src, srcOffset, count); }