protected virtual uint[] ValueToArray() { int count = 0; void *cch = null; try { cch = nsjs_localvalue_get_uint32array(this.Handle, ref count); uint[] buffer = new uint[count]; if (count > 0) { fixed(uint *data = buffer) { BufferExtension.memcpy(cch, data, sizeof(uint) * count); } } return(buffer); } finally { if (cch != null) { NSJSMemoryManagement.Free(cch); } } }
protected virtual sbyte[] ValueToArray() { void *cch = null; int count = 0; try { cch = nsjs_localvalue_get_int8array(this.Handle, ref count); sbyte[] buffer = new sbyte[count]; if (count > 0) { fixed(sbyte *data = buffer) { BufferExtension.memcpy(cch, data, (sizeof(sbyte) * count)); } } return(buffer); } finally { if (cch != null) { NSJSMemoryManagement.Free(cch); } } }
private unsafe void WriteBufferToClient(byte *buffer, long count, Action <Exception> callback) { Exception exception = null; if (buffer == null) { exception = new ArgumentNullException("buffer"); } else if (count <= 0) { exception = new ArgumentOutOfRangeException("count"); } if (exception != null) { if (callback != null) { callback(exception); } return; } Stream output = response.OutputStream; byte[] chunk = new byte[1400]; long offset = 0; lock (output) { while (offset < count && exception == null) { long rdsz = unchecked (count - offset); if (rdsz > chunk.Length) { rdsz = chunk.Length; } int len = unchecked ((int)rdsz); BufferExtension.memcpy(&buffer[offset], chunk, 0, len); try { output.Write(chunk, 0, len); } catch (Exception ex) { exception = ex; } offset = unchecked (offset + rdsz); } } if (callback != null) { callback(exception); } }
public static void *memcpy(void *src, void *dest, int count) { if (dest == null || src == null) { return(null); } if (dest == src && count <= 0) { return(dest); } BufferExtension.BlockCopy((byte *)src, 0, (byte *)dest, count); return(dest); }
public void Initialize() { var keys = BufferExtension.ReadParametrs().Select(e => e.Name).ToList(); foreach (var item in keys) { _buffer.DataFillEvents[item] += (e => { var _worker = new BackgroundWorker(e); _worker.ExecuteBulk(); }); } }
private byte[] CopyBuffer(byte[] value, int ofs, int len) { if ((ofs + len) > value.Length) { len = (value.Length - ofs); } if (ofs < 0 || ofs >= len) { len = 0; } byte[] cch = new byte[len]; BufferExtension.BlockCopy(value, ofs, cch); return(cch); }
private void Inversion(string key, byte[] sbox, byte *num, int len) { byte[] vk = new byte[sbox.Length]; BufferExtension.BlockCopy(sbox, vk, vk.Length); for (int i = 0, low = 0, high = 0, mid; i < len; i++) { low = (low + key.Length) % MaxbitWidth; high = (high + vk[i % MaxbitWidth]) % MaxbitWidth; byte b = vk[low]; vk[low] = vk[high]; vk[high] = b; mid = (vk[low] + vk[high]) % MaxbitWidth; num[i] ^= (byte)vk[mid]; } }