ReadInt16() public method

public ReadInt16 ( int offset ) : short
offset int
return short
Example #1
0
            object INativeType.GetValue(MemoryHolder /*!*/ owner, object readingFrom, int offset, bool raw)
            {
                object res;

                switch (_type)
                {
                case SimpleTypeKind.Boolean: res = owner.ReadByte(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;

                case SimpleTypeKind.Char: res = new string((char)owner.ReadByte(offset), 1); break;

                case SimpleTypeKind.SignedByte: res = GetIntReturn((int)(sbyte)owner.ReadByte(offset)); break;

                case SimpleTypeKind.UnsignedByte: res = GetIntReturn((int)owner.ReadByte(offset)); break;

                case SimpleTypeKind.SignedShort: res = GetIntReturn(owner.ReadInt16(offset, _swap)); break;

                case SimpleTypeKind.WChar: res = new string((char)owner.ReadInt16(offset), 1); break;

                case SimpleTypeKind.UnsignedShort: res = GetIntReturn((ushort)owner.ReadInt16(offset, _swap)); break;

                case SimpleTypeKind.VariantBool: res = owner.ReadInt16(offset, _swap) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;

                case SimpleTypeKind.SignedInt: res = GetIntReturn(owner.ReadInt32(offset, _swap)); break;

                case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset, _swap)); break;

                case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset, _swap)); break;

                case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset, _swap)); break;

                case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset, _swap)); break;

                case SimpleTypeKind.Double: res = GetDoubleReturn(owner.ReadInt64(offset, _swap)); break;

                case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset, _swap)); break;

                case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset, _swap)); break;

                case SimpleTypeKind.Object: res = GetObjectReturn(owner.ReadIntPtr(offset)); break;

                case SimpleTypeKind.Pointer: res = owner.ReadIntPtr(offset).ToPython(); break;

                case SimpleTypeKind.CharPointer: res = owner.ReadMemoryHolder(offset).ReadAnsiString(0); break;

                case SimpleTypeKind.WCharPointer: res = owner.ReadMemoryHolder(offset).ReadUnicodeString(0); break;

                case SimpleTypeKind.BStr: res = Marshal.PtrToStringBSTR(owner.ReadIntPtr(offset)); break;

                default:
                    throw new InvalidOperationException();
                }

                if (!raw && IsSubClass)
                {
                    res = PythonCalls.Call(this, res);
                }

                return(res);
            }
Example #2
0
            /// <summary>
            /// Helper function for reading char/wchar's.  This is used for reading from
            /// arrays and pointers to avoid creating lots of 1-char strings.
            /// </summary>
            internal char ReadChar(MemoryHolder /*!*/ owner, int offset)
            {
                switch (_type)
                {
                case SimpleTypeKind.Char: return((char)owner.ReadByte(offset));

                case SimpleTypeKind.WChar: return((char)owner.ReadInt16(offset));

                default: throw new InvalidOperationException();
                }
            }
Example #3
0
            object INativeType.GetValue(MemoryHolder/*!*/ owner, object readingFrom, int offset, bool raw) {
                object res;
                switch (_type) {
                    case SimpleTypeKind.Boolean: res = owner.ReadByte(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
                    case SimpleTypeKind.Char: res = new string((char)owner.ReadByte(offset), 1); break;
                    case SimpleTypeKind.SignedByte: res = GetIntReturn((int)(sbyte)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.UnsignedByte: res = GetIntReturn((int)owner.ReadByte(offset)); break;
                    case SimpleTypeKind.SignedShort: res = GetIntReturn((int)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.WChar: res = new string((char)owner.ReadInt16(offset), 1); break;
                    case SimpleTypeKind.UnsignedShort: res = GetIntReturn((int)(ushort)owner.ReadInt16(offset)); break;
                    case SimpleTypeKind.VariantBool: res = owner.ReadInt16(offset) != 0 ? ScriptingRuntimeHelpers.True : ScriptingRuntimeHelpers.False; break;
                    case SimpleTypeKind.SignedInt: res = GetIntReturn((int)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedInt: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.UnsignedLong: res = GetIntReturn((uint)owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.SignedLong: res = GetIntReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Single: res = GetSingleReturn(owner.ReadInt32(offset)); break;
                    case SimpleTypeKind.Double: res = GetDoubleReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.UnsignedLongLong: res = GetIntReturn((ulong)owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.SignedLongLong: res = GetIntReturn(owner.ReadInt64(offset)); break;
                    case SimpleTypeKind.Object: res = GetObjectReturn(owner.ReadIntPtr(offset)); break;
                    case SimpleTypeKind.Pointer: res = owner.ReadIntPtr(offset).ToPython(); break;
                    case SimpleTypeKind.CharPointer: res = owner.ReadMemoryHolder(offset).ReadAnsiString(0); break;
                    case SimpleTypeKind.WCharPointer: res = owner.ReadMemoryHolder(offset).ReadUnicodeString(0); break;
                    default:
                        throw new InvalidOperationException();
                }

                if (!raw && IsSubClass) {
                    res = PythonCalls.Call(this, res);
                }

                return res;
            }
Example #4
0
 /// <summary>
 /// Helper function for reading char/wchar's.  This is used for reading from
 /// arrays and pointers to avoid creating lots of 1-char strings.
 /// </summary>
 internal char ReadChar(MemoryHolder/*!*/ owner, int offset) {
     switch (_type) {
         case SimpleTypeKind.Char: return (char)owner.ReadByte(offset);
         case SimpleTypeKind.WChar: return (char)owner.ReadInt16(offset);
         default: throw new InvalidOperationException();
     }
 }
Example #5
0
            public object this[Slice index] {
                get {
                    if (index.stop == null)
                    {
                        throw PythonOps.ValueError("slice stop is required");
                    }

                    int start = index.start != null ? (int)index.start : 0;
                    int stop  = index.stop != null ? (int)index.stop : 0;
                    int step  = index.step != null ? (int)index.step : 1;

                    if (step < 0 && index.start == null)
                    {
                        throw PythonOps.ValueError("slice start is required for step < 0");
                    }

                    if (start < 0)
                    {
                        start = 0;
                    }
                    INativeType type     = ((PointerType)NativeType)._type;
                    SimpleType  elemType = type as SimpleType;

                    if ((stop < start && step > 0) || (start < stop && step < 0))
                    {
                        if (elemType != null)
                        {
                            if (elemType._type == SimpleTypeKind.Char)
                            {
                                return(Bytes.Empty);
                            }
                            if (elemType._type == SimpleTypeKind.WChar)
                            {
                                return(string.Empty);
                            }
                        }
                        return(new PythonList());
                    }

                    MemoryHolder address = MemHolder.ReadMemoryHolder(0);
                    if (elemType != null)
                    {
                        if (elemType._type == SimpleTypeKind.Char)
                        {
                            Debug.Assert(((INativeType)elemType).Size == 1);
                            var sb = new MemoryStream();

                            for (int i = start; stop > start ? i <stop : i> stop; i += step)
                            {
                                sb.WriteByte(address.ReadByte(i));
                            }

                            return(Bytes.Make(sb.ToArray()));
                        }
                        if (elemType._type == SimpleTypeKind.WChar)
                        {
                            int elmSize = ((INativeType)elemType).Size;
                            var sb      = new StringBuilder();

                            for (int i = start; stop > start ? i <stop : i> stop; i += step)
                            {
                                sb.Append((char)address.ReadInt16(checked (i * elmSize)));
                            }

                            return(sb.ToString());
                        }
                    }

                    PythonList res = new PythonList((stop - start) / step);
                    for (int i = start; stop > start ? i <stop : i> stop; i += step)
                    {
                        res.AddNoLock(
                            type.GetValue(address, this, checked (type.Size * i), false)
                            );
                    }
                    return(res);
                }
            }