private static unsafe void CheckEntry(Int32 i, ref GVHeaderEntry entry, SByte *contentPtr) { for (Int32 r = 0; r < 2; r++) { Int32 lastCharacter = entry.Offset + entry.Size - 1; for (int k = entry.Offset; k < lastCharacter; k++) { if (contentPtr[k] == 0x00) { goto check; } } if (contentPtr[lastCharacter] != 0x00) { goto check; } return; @check: if (TryCorrectEntry(i, ref entry)) { continue; } throw new NotSupportedException($"Unexcepted character: 0x{contentPtr[lastCharacter]:X2} at position {lastCharacter}. Expected: 0x00"); } }
public unsafe static SByte ReadSByte(this Stream stream) { var value = (byte)stream.ReadByte(); SByte *ptr = (SByte *)&value; return(ptr[0]); }
public void Read(SByte *p, Int32 min, Int32 max) { var token = _GetNumber(false); var value = SByte.Parse(token); Runtime.RTCheckRange(value, min, max); *p = value; }
/// <summary> /// Liefert den Wert von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset"></param> unsafe static public SByte CopySByte(this byte [] Array, Int32 Offset) { fixed(byte *ptr = Array) { SByte *vpSByte = (SByte *)(ptr + Offset); return(*vpSByte); } }
public IReadOnlyCollection <String> ReadLines() { unsafe { Int32 headerOffset = Positive(_br.ReadInt32()); Int32 headerCount = Positive(_br.ReadInt32()); Int32 headerSize = checked (headerCount * sizeof(GVHeaderEntry)); Int32 contentOffset = Positive(_br.ReadInt32()); Int32 contentSize = Positive(_br.ReadInt32()); _stream.SetPosition(headerOffset); Byte[] header = _stream.ReadBytes(headerSize); _stream.SetPosition(contentOffset); Byte[] content = _stream.ReadBytes(contentSize); String[] result = new String[headerCount]; fixed(Byte *headerBytes = header) fixed(Byte * contentBytes = content) { GVHeaderEntry *entriesPtr = (GVHeaderEntry *)headerBytes; SByte * contentPtr = (SByte *)contentBytes; for (Int32 i = 0; i < headerCount; i++) { if (IsEmpty(entriesPtr, i)) { result[i] = $"{i:D4}|"; continue; } GVHeaderEntry entry = entriesPtr[i]; CheckEntry(i, ref entry, contentPtr); Int32 offset = InRange(entry.Offset, minValue: 0, maxValue: contentSize - 1); Int32 size = InRange(entry.Size, minValue: 2, maxValue: contentSize - offset); // \0 terminated strings UInt32 value = entry.Value; UInt32 mask = entry.Mask; String name = new String(contentPtr, offset, size - 1, Encoding.ASCII); if ((value & mask) != value) { throw new InvalidDataException($"Value 0x[{value:X8}] of the variable [{i:D4}:{name}] is out of mask [{mask:X8}]."); } FormatTypeAndValue(mask, value, out var formattedType, out var formattedValue); result[i] = $"{i:D4}| {formattedType} {name} = {formattedValue}"; } } return(result); } }
/// <summary> /// Kopiert die Werte einzeln via *ptr++. /// </summary> /// <param name="Source"></param> /// <param name="Target"></param> /// <param name="Length"></param> unsafe static public void CopySBytes(SByte *Source, SByte *Target, int Length) { for (int i = 0; i < Length; i++) { *Target = *Source; // Source++; Target++; } }
/// <summary> /// Liefert den Wert (und neuen Offset) von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der gelesen wird.</param> unsafe static public (SByte, Int32) CopySByteOffset(this byte [] Array, Int32 Offset) { fixed(byte *ptr = Array) { SByte *vpSByte = (SByte *)(ptr + Offset); return(*vpSByte, Offset + sizeof(SByte)); } }
/// <summary> /// Kopiert den Wert an die angegebene Stelle in das Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der geschrieben wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> /// <param name="Value"></param> unsafe static public void CopySByte(this byte [] Array, ref Int32 Offset, SByte Value) { fixed(byte *ptr = Array) { SByte *vp = (SByte *)(ptr + Offset); *vp = Value; Offset += sizeof(SByte); } }
/// <summary> /// Kopiert den Wert an die angegebene Stelle in das Byte-Array und liefert den neuen Offset zurück. /// </summary> /// <param name="Array"></param> /// <param name="Offset"></param> /// <param name="Value"></param> /// <returns>Liefert den neuen Offset.</returns> unsafe static public Int32 CopySByte(this byte [] Array, Int32 Offset, SByte Value) { fixed(byte *ptr = Array) { SByte *vp = (SByte *)(ptr + Offset); *vp = Value; } return(Offset + sizeof(SByte)); }
/// <summary> /// Liefert die Bytes ab der Stelle <paramref name="Offset"/> als Wert. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Array"></param> /// <param name="Offset">Position, ab der gelesen wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> /// <returns></returns> unsafe static public dynamic CopyValue <T> (this byte [] Array, ref Int32 Offset) where T : unmanaged { try { fixed(byte *ptr = Array) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.SByte: SByte *vpSByte = (SByte *)(ptr + Offset); return(*vpSByte); case TypeCode.Byte: Byte *vpByte = (Byte *)(ptr + Offset); return(*vpByte); case TypeCode.Int16: Int16 *vpInt16 = (Int16 *)(ptr + Offset); return(*vpInt16); case TypeCode.UInt16: UInt16 *vpUInt16 = (UInt16 *)(ptr + Offset); return(*vpUInt16); case TypeCode.Int32: Int32 *vpInt32 = (Int32 *)(ptr + Offset); return(*vpInt32); case TypeCode.UInt32: UInt32 *vpUInt32 = (UInt32 *)(ptr + Offset); return(*vpUInt32); case TypeCode.Int64: Int64 *vpInt64 = (Int64 *)(ptr + Offset); return(*vpInt64); case TypeCode.UInt64: UInt64 *vpUInt64 = (UInt64 *)(ptr + Offset); return(*vpUInt64); case TypeCode.Char: Char *vpChar = (Char *)(ptr + Offset); return(*vpChar); case TypeCode.Boolean: Boolean *vpBoolean = (Boolean *)(ptr + Offset); return(*vpBoolean); } } } finally { Offset += sizeof(T); } throw new Exception("Not implemented!"); }
public static IReadOnlyList <TXString> ReadStrings(Stream stream) { unsafe { TXHeader header = stream.ReadStruct <TXHeader>(); header.Check(); Int32 count = header.Count; // Int32 dataSize = header.DataSize; Int32 headerSize = count * sizeof(TXEntry); Byte[] entriesHeader = stream.ReadBytes(headerSize); Byte[] data = stream.ReadToEnd(); // .ReadBytes(dataSize); https://github.com/Albeoris/Septerra/issues/1 List <TXString> result = new List <TXString>(count); fixed(Byte *entriesPtr = entriesHeader) fixed(Byte * dataPtr = data) { TXEntry *entries = (TXEntry *)entriesPtr; SByte * str = (SByte *)dataPtr; for (Int32 i = 0; i < count; i++) { TXEntry entry = entries[i]; Int32 offset = checked ((Int32)(entry.Offset - headerSize - sizeof(TXHeader))); Int32 size = 0; for (Int32 c = 0; c < entry.Size; c++) { if (offset + c >= data.Length) { throw new EndOfStreamException($"Entry: {i}, Offset: {offset}, Size: {entry.Size} is out of data segment: {data.Length}"); } SByte ch = str[offset + c]; if (ch == 0) { break; } str[offset + c] = (SByte)TXEncoding.ToText((Byte)ch); size++; } String line = new String(str, offset, size); result.Add(new TXString(entry.Index, line)); } return(result); } } }
/// <summary> /// Liefert den Wert von der angegebenen Stelle im Byte-Array. /// </summary> /// <param name="Array"></param> /// <param name="Offset">Position, ab der geschrieben wird. Erhöht sich um die Anzhal der gelesenen Bytes!</param> unsafe static public SByte CopySByte(this byte [] Array, ref Int32 Offset) { try { fixed(byte *ptr = Array) { SByte *vpSByte = (SByte *)(ptr + Offset); return(*vpSByte); } } finally { Offset += sizeof(SByte); } }
public unsafe void RunBasicScenario_LoadAligned() { TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned)); SByte localData = (sbyte)2; SByte *ptr = &localData; var result = Sse41.Insert( Sse2.LoadAlignedVector128((SByte *)(_dataTable.inArrayPtr)), *ptr, 1 ); Unsafe.Write(_dataTable.outArrayPtr, result); ValidateResult(_dataTable.inArrayPtr, *ptr, _dataTable.outArrayPtr); }
/// <summary> /// Writes a list of System.SByte integers to the current stream using the specified buffer. /// </summary> /// <param name="stream">The stream to write.</param> /// <param name="array">A list of System.SByte integers.</param> /// <param name="startIndex">A position in the list where the writing starts.</param> /// <param name="count">The number of integers to be written into the current stream. /// <para>!!! Note this number should be no larger than the number of integers from <paramref name="startIndex" /> to the end of the array.</para></param> /// <param name="buffer">A byte array used to temporarily store data to write.</param> public unsafe static void WriteSBytes(this Stream stream, IList <SByte> list, int startIndex, int count, byte[] buffer) { fixed(byte *ptr = buffer) { SByte *iptr2 = (SByte *)ptr; for (int i = 0, j = startIndex; i < count;) { iptr2[i] = list[j]; ++i; ++j; } } stream.Write(buffer, 0, buffer.Length); }
private static unsafe String ReadMessage(SByte *textPtr, Int32 currentOffset, Int32 messageLength, Int32 bufferSize, Encoding encoding) { if (currentOffset + messageLength > bufferSize) { throw new InvalidDataException($"Invalid text info (Offset: {currentOffset}, Size: {messageLength}) is out of bounds ({bufferSize})."); } String message = new String(textPtr, currentOffset, messageLength, encoding); var lastCharacter = textPtr[currentOffset + messageLength]; if (lastCharacter != 0 /* {End} */ && lastCharacter != 2 /* {Line} */) { throw new InvalidDataException($"Text must be a null-terminated string. Occured text (Offset: {currentOffset}, Size: {messageLength}): {message}"); } return(message); }
public static IReadOnlyList <String> FromBytes(Byte[] buff, Encoding encoding) { List <String> monologues = new List <String>(); Int32 bufferSize = buff.Length; if (bufferSize < 4) { return(monologues); } unsafe { fixed(Byte *ptr = &buff[0]) { SByte *textPtr = (SByte *)(ptr); ReadMessages(textPtr, bufferSize, monologues, encoding); } } return(monologues); }
private static unsafe void ReadMessages(SByte *textPtr, Int32 bufferSize, List <String> messages, Encoding encoding) { Int32 *offsets = (Int32 *)textPtr; Int32 count = GetMessageNumber(bufferSize, offsets); if (count == 0) { return; } messages.Capacity = count; Int32 currentOffset = offsets[0]; for (Int32 i = 1; i < count; i++) { Int32 nextOffset = offsets[i]; if (nextOffset == currentOffset) { messages.Add(String.Empty); continue; } Int32 messageLength = nextOffset - currentOffset - 1; String message = ReadMessage(textPtr, currentOffset, messageLength, bufferSize, encoding); messages.Add(message); currentOffset = nextOffset; } Int32 lastMessageLength = bufferSize - currentOffset - 1; String lastMessage = ReadMessage(textPtr, currentOffset, lastMessageLength, bufferSize, encoding); messages.Add(lastMessage); }
public string GetErrorMessage() { // This can work even after XxflateEnd(). if (ZNullPtr.Equals(_zStream.msg)) { return(String.Empty); } unsafe { StringBuilder sb = new StringBuilder(); SByte * pMessage = (SByte *)_zStream.msg; char c; do { c = (char)*pMessage; pMessage++; sb.Append(c); } while ((sbyte)c != 0); return(sb.ToString()); } }
private static extern IntPtr _build_parsed_json44(SByte *buf, IntPtr /*size_t*/ len, Byte reallocifneeded);
private static extern IntPtr /*size_t*/ _jsonminify22(SByte *buf, IntPtr /*size_t*/ len, SByte * @out);
private static extern void _aligned_free_char8(SByte *memblock);
private static extern Byte _find_structural_bits28(SByte *buf, IntPtr /*size_t*/ len, IntPtr pj);
private static extern IntPtr /*size_t*/ _jsonminify24(IntPtr p, SByte * @out);
internal static extern void glNormal3bv(SByte *v);
internal static extern void glColor3bv(SByte *v);
private static extern Int32 _unified_machine38(SByte *buf, IntPtr /*size_t*/ len, IntPtr pj);
private static extern Int32 _json_parse40(SByte *buf, IntPtr /*size_t*/ len, IntPtr pj, Byte reallocifneeded);
public String(SByte *value, int startIndex, int length, System.Text.Encoding enc) { }
public String(SByte *value, int startIndex, int length) { }
public String(SByte *value) { }