internal object GetRawValue(MemoryHolder owner, int offset) { Debug.Assert(IsStringType); SimpleType st = (SimpleType)_type; if (st._type == SimpleTypeKind.Char) { return(owner.ReadBytes(offset, _length)); } else { return(owner.ReadUnicodeString(offset, _length)); } }
/// <summary> /// Helper function for translating from memset to NT's FillMemory API. /// </summary> private static IntPtr StringAt(IntPtr src, int len) { byte[] res; if (len == -1) { res = MemoryHolder.ReadBytes(src, 0); } else { res = MemoryHolder.ReadBytes(src, 0, len); } return(GCHandle.ToIntPtr(GCHandle.Alloc(res))); }
object INativeType.GetValue(MemoryHolder owner, object readingFrom, int offset, bool raw) { if (IsStringType) { SimpleType st = (SimpleType)_type; if (st._type == SimpleTypeKind.Char) { IList <byte> str = owner.ReadBytes(offset, _length); // remove any trailing nulls for (int i = 0; i < str.Count; i++) { if (str[i] == 0) { return(str.Substring(0, i)); } } return(str); } else { string str = owner.ReadUnicodeString(offset, _length); // remove any trailing nulls for (int i = 0; i < str.Length; i++) { if (str[i] == '\x00') { return(str.Substring(0, i)); } } return(str); } } _Array arr = (_Array)CreateInstance(Context.SharedContext); arr._memHolder = new MemoryHolder(owner.UnsafeAddress.Add(offset), ((INativeType)this).Size, owner); return(arr); }
internal object GetRawValue(MemoryHolder owner, int offset) { Debug.Assert(_type is SimpleType st && st._type == SimpleTypeKind.Char); return(owner.ReadBytes(offset, _length)); }