static extern int Blah( [MarshalAs(UnmanagedType.I4)] int i, string s, union u, sparse sp, [In, Out] string inout, StringBuilder sb, IntPtr ip, out bool ob, ref bytes bs);
public static void ToBytes(bytes s, fe25519 h) { fe25519 t = stackalloc int[ArraySize]; Reduce(t, h); s[0] = (byte)(t[0] >> 0); s[1] = (byte)(t[0] >> 8); s[2] = (byte)(t[0] >> 16); s[3] = (byte)((t[0] >> 24) | (t[1] * (1 << 2))); s[4] = (byte)(t[1] >> 6); s[5] = (byte)(t[1] >> 14); s[6] = (byte)((t[1] >> 22) | (t[2] * (1 << 3))); s[7] = (byte)(t[2] >> 5); s[8] = (byte)(t[2] >> 13); s[9] = (byte)((t[2] >> 21) | (t[3] * (1 << 5))); s[10] = (byte)(t[3] >> 3); s[11] = (byte)(t[3] >> 11); s[12] = (byte)((t[3] >> 19) | (t[4] * (1 << 6))); s[13] = (byte)(t[4] >> 2); s[14] = (byte)(t[4] >> 10); s[15] = (byte)(t[4] >> 18); s[16] = (byte)(t[5] >> 0); s[17] = (byte)(t[5] >> 8); s[18] = (byte)(t[5] >> 16); s[19] = (byte)((t[5] >> 24) | (t[6] * (1 << 1))); s[20] = (byte)(t[6] >> 7); s[21] = (byte)(t[6] >> 15); s[22] = (byte)((t[6] >> 23) | (t[7] * (1 << 3))); s[23] = (byte)(t[7] >> 5); s[24] = (byte)(t[7] >> 13); s[25] = (byte)((t[7] >> 21) | (t[8] * (1 << 4))); s[26] = (byte)(t[8] >> 4); s[27] = (byte)(t[8] >> 12); s[28] = (byte)((t[8] >> 20) | (t[9] * (1 << 6))); s[29] = (byte)(t[9] >> 2); s[30] = (byte)(t[9] >> 10); s[31] = (byte)(t[9] >> 18); }
/// <summary>Gets the string for the specified 7Bit ASCII bytes.</summary> /// <param name="bytes">Bytes to decode.</param> /// <param name="start">Startindex at the array to decode.</param> /// <param name="count">Length in bytes to decode.</param> /// <param name="termination">if set to <c>true</c> [obey termination].</param> /// <returns>The string.</returns> /// <exception cref="ArgumentNullException">bytes.</exception> /// <exception cref="InvalidDataException">Byte '{0}' at index '{1}' is not a valid ASCII character!.</exception> public static string GetString(byte[] bytes, int start, int count, bool termination = false) => new(GetChars(bytes, start, count, termination));
=> Apply(new DigitalAssetCreated(DigitalAssetId, name, bytes, contentType));
WritePng(bytes, width, height, outputFile);
var(bytes, start, len) = action(m_SendBuffer, 0);
mm.file = (HttpPostedFileBase) new MemoryPostedFile(bytes, FilePath, filename);
private static void DoFill(string operation, int Unit, string filler, int maxthreads, ulong availablePMem, int Units, out DateTime tstart, out string totalbytes) { bytes[] arrayofbytes; tstart = DateTime.Now; byte[] lastbytes; ulong remaining; // this causes the memory to become committed to the process arrayofbytes = new bytes[Units]; for (int i = 0; i < Units; i++) { arrayofbytes[i].sequence = new byte[Unit]; } //commit last bytes of memory here remaining = availablePMem - ((ulong)Units * (ulong)Unit); lastbytes = new byte[remaining]; double factor = (double)Unit / (double)GB; totalbytes = ((double)Units * factor + (double)lastbytes.Length / (double)GB).ToString("0.00"); Console.WriteLine(totalbytes + " GB committed to be filled with " + filler); System.Threading.Thread.MemoryBarrier(); // RNGCryptoServiceProvider CSP = new RNGCryptoServiceProvider(); // RNGCryptoServiceProvider CSP = new RNGCryptoServiceProvider(); // RandomNumberGenerator rnd = RNGCryptoServiceProvider.Create(); Random rnd = new Random(); // runs fill operations on segments of memory in parallel to reduce elapsed time Parallel.For(0, Units, new ParallelOptions { MaxDegreeOfParallelism = maxthreads }, i => { // Console.WriteLine("debug -> i=" + i + " sequence length=" + arrayofbytes[i].sequence.Length); if (operation == "r") { // Console.Write("x"); // CSP.GetBytes(arrayofbytes[i].sequence); // rnd.NextBytes(arrayofbytes[i].sequence); rnd.NextBytes(arrayofbytes[i].sequence); } else if (operation == "f") { for (int n = 0; n < Unit; n++) { arrayofbytes[i].sequence[n] = 255; } } else { Array.Clear(arrayofbytes[i].sequence, 0, Unit); } if (i % (GB / Unit) == 0) { Console.Write("."); // progress indicator } }); // fill the remaining bytes if (operation == "r") { rnd.NextBytes(lastbytes); } // CSP.GetBytes(lastbytes); else if (operation == "f") { for (uint n = 0; n < remaining; n++) { lastbytes[n] = 255; } } else { Array.Clear(lastbytes, 0, (int)remaining); } //CSP.Dispose(); //rnd.Dispose(); arrayofbytes = null; lastbytes = null; }
public static ushort ByteDeserialize(Type _type, object _ref, byte[] _buffer, ushort _idx) { ushort len; try { System.Reflection.FieldInfo[] fields = _ref.GetType().GetFields(); foreach (System.Reflection.FieldInfo field in fields) { if (field.IsNotSerialized) { continue; } if (field.IsStatic) { continue; } if (field.FieldType.IsArray) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; // elementos Array arr = Activator.CreateInstance(field.FieldType, len) as Array; for (int i = 0; i < len; ++i) { object ele = Activator.CreateInstance(field.FieldType.GetElementType()); _idx = ByteDeserialize(field.FieldType.GetElementType(), ele, _buffer, _idx); Debug.Log("Deserialize!! " + ele + " " + ele.GetType()); arr.SetValue(ele, i); } field.SetValue(_ref, arr); } else { if (field.FieldType == typeof(byte)) { field.SetValue(_ref, (byte)BitConverter.ToChar(_buffer, _idx)); _idx += 1; } else if (field.FieldType == typeof(sbyte)) { field.SetValue(_ref, (sbyte)BitConverter.ToChar(_buffer, _idx)); _idx += 1; } else if (field.FieldType == typeof(bool)) { field.SetValue(_ref, _buffer[_idx] == 1); _idx += 1; } else if (field.FieldType == typeof(char)) { field.SetValue(_ref, (char)BitConverter.ToChar(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(short)) { field.SetValue(_ref, BitConverter.ToInt16(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(ushort)) { field.SetValue(_ref, BitConverter.ToUInt16(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(int)) { field.SetValue(_ref, BitConverter.ToInt32(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(uint)) { field.SetValue(_ref, BitConverter.ToUInt32(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(float)) { field.SetValue(_ref, BitConverter.ToSingle(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(string)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; string str = System.Text.Encoding.UTF8.GetString(_buffer, _idx, len); field.SetValue(_ref, str); _idx += len; } else if (field.FieldType == typeof(bytes)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; bytes tmp = new bytes(len); Array.Copy(_buffer, _idx, tmp.Buffer, 0, len); _idx += len; field.SetValue(_ref, tmp); } else { object obj = Activator.CreateInstance(field.FieldType); _idx = ByteDeserialize(field.FieldType, obj, _buffer, _idx); field.SetValue(_ref, obj); } } } } catch (Exception e) { UnityEngine.Debug.LogError("Exception deserializing: " + e.ToString()); } return(_idx); }
System.Buffers.Binary.BinaryPrimitives.WriteInt32BigEndian(memoryframe.Span, RSocketProtocol.MessageFrame(bytes, endOfMessage)); output.Advance(sizeof(int) + bytes);
ReadValue(ref v, ref bytes, manifest);
return(new FileContentResult(bytes, contentType));
Bits(byte[] bytes, int index, int numBits) => byteBits = ToByteBits(bytes, index, numBits);
CreateFromJson(bytes, pattern, string.Empty);
public static ushort ByteDeserializeLiteral(Type _type, ref object _ref, byte[] _buffer, ushort _idx) { ushort len; if (_type == typeof(byte)) { _ref = (byte)BitConverter.ToChar(_buffer, _idx); _idx += 1; } else if (_type == typeof(sbyte)) { _ref = (sbyte)BitConverter.ToChar(_buffer, _idx); _idx += 1; } else if (_type == typeof(bool)) { _ref = (_buffer[_idx] == 1); _idx += 1; } else if (_type == typeof(char)) { _ref = (char)BitConverter.ToChar(_buffer, _idx); _idx += 2; } else if (_type == typeof(short)) { _ref = BitConverter.ToInt16(_buffer, _idx); _idx += 2; } else if (_type == typeof(ushort)) { _ref = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; } else if (_type == typeof(int)) { _ref = BitConverter.ToInt32(_buffer, _idx); _idx += 4; } else if (_type == typeof(uint)) { _ref = BitConverter.ToUInt32(_buffer, _idx); _idx += 4; } else if (_type == typeof(float)) { _ref = BitConverter.ToSingle(_buffer, _idx); _idx += 4; } else if (_type == typeof(string)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; string str = System.Text.Encoding.UTF8.GetString(_buffer, _idx, len); _ref = str; _idx += len; } else if (_type == typeof(bytes)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; bytes tmp = new bytes(len); Array.Copy(_buffer, _idx, tmp.Buffer, 0, len); _idx += len; _ref = tmp; } else { object obj = Activator.CreateInstance(_type); _idx = ByteDeserialize(_type, obj, _buffer, _idx); _ref = obj; } return(_idx); }
public static ushort ByteDeserialize(Type _type, object _ref, byte[] _buffer, ushort _idx) { ushort len; try { System.Reflection.FieldInfo[] fields = _ref.GetType().GetFields(); foreach (System.Reflection.FieldInfo field in fields) { if (field.IsNotSerialized) { continue; } if (field.IsStatic) { continue; } if (field.FieldType.IsArray) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; // elementos Array arr = Activator.CreateInstance(field.FieldType, len) as Array; for (int i = 0; i < len; ++i) { //¿Porque esta mierda de ñapa a continuacion? //porque a algun crack, en alguna parte del mundo //le parecio que un string no era un tipo primitivo //ni tampoco un array //¿que es para ti un string, amigo desconocido? //esta chapuza te la dedico :) if ((field.FieldType.GetElementType() == typeof(string))) { ushort strlen = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; string str = System.Text.Encoding.UTF8.GetString(_buffer, _idx, strlen); arr.SetValue(str, i); _idx += strlen; } else { object ele = Activator.CreateInstance(field.FieldType.GetElementType()); if (field.FieldType.GetElementType().IsPrimitive) { _idx = ByteDeserializeLiteral(field.FieldType.GetElementType(), ref ele, _buffer, _idx); } else { _idx = ByteDeserialize(field.FieldType.GetElementType(), ele, _buffer, _idx); } arr.SetValue(ele, i); } } field.SetValue(_ref, arr); } else { if (field.FieldType == typeof(byte)) { field.SetValue(_ref, (byte)BitConverter.ToChar(_buffer, _idx)); _idx += 1; } else if (field.FieldType == typeof(sbyte)) { field.SetValue(_ref, (sbyte)BitConverter.ToChar(_buffer, _idx)); _idx += 1; } else if (field.FieldType == typeof(bool)) { field.SetValue(_ref, _buffer[_idx] == 1); _idx += 1; } else if (field.FieldType == typeof(char)) { field.SetValue(_ref, (char)BitConverter.ToChar(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(short)) { field.SetValue(_ref, BitConverter.ToInt16(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(ushort)) { field.SetValue(_ref, BitConverter.ToUInt16(_buffer, _idx)); _idx += 2; } else if (field.FieldType == typeof(int)) { field.SetValue(_ref, BitConverter.ToInt32(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(uint)) { field.SetValue(_ref, BitConverter.ToUInt32(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(float)) { field.SetValue(_ref, BitConverter.ToSingle(_buffer, _idx)); _idx += 4; } else if (field.FieldType == typeof(string)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; string str = System.Text.Encoding.UTF8.GetString(_buffer, _idx, len); field.SetValue(_ref, str); _idx += len; } else if (field.FieldType == typeof(bytes)) { len = BitConverter.ToUInt16(_buffer, _idx); _idx += 2; bytes tmp = new bytes(len); Array.Copy(_buffer, _idx, tmp.Buffer, 0, len); _idx += len; field.SetValue(_ref, tmp); } else { object obj = Activator.CreateInstance(field.FieldType); _idx = ByteDeserialize(field.FieldType, obj, _buffer, _idx); field.SetValue(_ref, obj); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(_idx); }
public static ushort ByteSerializeLiteral(Type _type, object _ref, ref byte[] _buffer, ushort _idx) { if (_type == typeof(byte)) { Array.Copy(BitConverter.GetBytes((byte)_ref), 0, _buffer, _idx, 1); _idx += 1; } else if (_type == typeof(sbyte)) { Array.Copy(BitConverter.GetBytes((sbyte)_ref), 0, _buffer, _idx, 1); _idx += 1; } else if (_type == typeof(bool)) { _buffer[_idx] = (byte)((bool)_ref ? 1 : 0); _idx += 1; } else if (_type == typeof(char)) { Array.Copy(BitConverter.GetBytes((char)_ref), 0, _buffer, _idx, 2); _idx += 2; } else if (_type == typeof(short)) { Array.Copy(BitConverter.GetBytes((short)_ref), 0, _buffer, _idx, 2); _idx += 2; } else if (_type == typeof(ushort)) { Array.Copy(BitConverter.GetBytes((ushort)_ref), 0, _buffer, _idx, 2); _idx += 2; } else if (_type == typeof(int)) { Array.Copy(BitConverter.GetBytes((int)_ref), 0, _buffer, _idx, 4); _idx += 4; } else if (_type == typeof(uint)) { Array.Copy(BitConverter.GetBytes((uint)_ref), 0, _buffer, _idx, 4); _idx += 4; } else if (_type == typeof(float)) { Array.Copy(BitConverter.GetBytes((float)_ref), 0, _buffer, _idx, 4); _idx += 4; } else if (_type == typeof(string)) { string tmpStr = (string)_ref; if (tmpStr != string.Empty && tmpStr != null) { byte[] str = System.Text.Encoding.UTF8.GetBytes(tmpStr); Array.Copy(BitConverter.GetBytes(str.Length), 0, _buffer, _idx, 2);; Array.Copy(str, 0, _buffer, _idx + 2, str.Length); _idx += (ushort)(str.Length + 2); } else { Array.Copy(BitConverter.GetBytes((ushort)0), 0, _buffer, _idx, 2); _idx += 2; } } else if (_type == typeof(bytes)) { bytes tmp = _ref as bytes; Array.Copy(BitConverter.GetBytes(tmp.Length), 0, _buffer, _idx, 2); _idx += 2; Array.Copy(tmp.Buffer as byte[], 0, _buffer, _idx, tmp.Length); _idx += tmp.Length; } else { _idx = ByteSerialize(_type, _ref, ref _buffer, _idx); } return(_idx); }
public static ushort ByteSerialize(Type _type, object _ref, ref byte[] _buffer, ushort _idx) { System.Reflection.FieldInfo[] fields = _type.GetFields(); foreach (System.Reflection.FieldInfo field in fields) { if (field.IsNotSerialized) { continue; } if (field.IsStatic) { continue; } if (field.FieldType.IsArray) { Array array = field.GetValue(_ref) as Array; int len = array.Length; Array.Copy(BitConverter.GetBytes(len), 0, _buffer, _idx, 2); _idx += 2; foreach (object obj in array) { _idx = ByteSerialize(obj.GetType(), obj, ref _buffer, _idx); } } else { if (field.FieldType == typeof(byte)) { Array.Copy(BitConverter.GetBytes((byte)field.GetValue(_ref)), 0, _buffer, _idx, 1); _idx += 1; } else if (field.FieldType == typeof(sbyte)) { Array.Copy(BitConverter.GetBytes((sbyte)field.GetValue(_ref)), 0, _buffer, _idx, 1); _idx += 1; } else if (field.FieldType == typeof(bool)) { _buffer[_idx] = (byte)((bool)field.GetValue(_ref) ? 1 : 0); _idx += 1; } else if (field.FieldType == typeof(char)) { Array.Copy(BitConverter.GetBytes((char)field.GetValue(_ref)), 0, _buffer, _idx, 2); _idx += 2; } else if (field.FieldType == typeof(short)) { Array.Copy(BitConverter.GetBytes((short)field.GetValue(_ref)), 0, _buffer, _idx, 2); _idx += 2; } else if (field.FieldType == typeof(ushort)) { Array.Copy(BitConverter.GetBytes((ushort)field.GetValue(_ref)), 0, _buffer, _idx, 2); _idx += 2; } else if (field.FieldType == typeof(int)) { Array.Copy(BitConverter.GetBytes((int)field.GetValue(_ref)), 0, _buffer, _idx, 4); _idx += 4; } else if (field.FieldType == typeof(uint)) { Array.Copy(BitConverter.GetBytes((uint)field.GetValue(_ref)), 0, _buffer, _idx, 4); _idx += 4; } else if (field.FieldType == typeof(float)) { Array.Copy(BitConverter.GetBytes((float)field.GetValue(_ref)), 0, _buffer, _idx, 4); _idx += 4; } else if (field.FieldType == typeof(string)) { string tmpStr = (string)field.GetValue(_ref); if (tmpStr != string.Empty && tmpStr != null) { byte[] str = System.Text.Encoding.UTF8.GetBytes(tmpStr); Array.Copy(BitConverter.GetBytes(str.Length), 0, _buffer, _idx, 2);; Array.Copy(str, 0, _buffer, _idx + 2, str.Length); _idx += (ushort)(str.Length + 2); } else { Array.Copy(BitConverter.GetBytes((ushort)0), 0, _buffer, _idx, 2); _idx += 2; } } else if (field.FieldType == typeof(bytes)) { bytes tmp = field.GetValue(_ref) as bytes; Array.Copy(BitConverter.GetBytes(tmp.Length), 0, _buffer, _idx, 2); _idx += 2; Array.Copy(tmp.Buffer as byte[], 0, _buffer, _idx, tmp.Length); _idx += tmp.Length; } else { _idx = ByteSerialize(field.FieldType, field.GetValue(_ref), ref _buffer, _idx); } } } return(_idx); }
static void Main(string[] args) { var o = new bytes { vals = new int[] { 0 } }; }
/// <summary> /// Performs an explicit conversion from <see cref="T:byte[]"/> to <see cref="Blittable16"/>. /// </summary> /// <param name="bytes">The bytes.</param> /// <returns>The result of the conversion.</returns> public static explicit operator Blittable16([NotNull] byte[] bytes) => new Blittable16(bytes);
public unsafe NSMutableData(void *bytes, int length) => m_Self = CreateWithBytes(bytes, length);