예제 #1
0
            public override BigInteger write(CodeContext /*!*/ context, object b)
            {
                byte[] bArray = b as byte[];
                if (bArray != null)
                {
                    return(write(bArray));
                }

                Bytes bBytes = b as Bytes;

                if (bBytes != null)
                {
                    return(write(bBytes));
                }

                ArrayModule.array bPythonArray = b as ArrayModule.array;
                if (bPythonArray != null)
                {
                    return(write(bPythonArray.ToByteArray()));
                }

                ICollection <byte> bCollection = b as ICollection <byte>;

                if (bCollection != null)
                {
                    return(write(bCollection));
                }

                EnsureWritable();

                throw PythonOps.TypeError("expected a readable buffer object");
            }
예제 #2
0
            public _Array from_buffer_copy(ArrayModule.array array, int offset = 0)
            {
                ValidateArraySizes(array, offset, ((INativeType)this).Size);

                _Array res = (_Array)CreateInstance(Context.SharedContext);

                res._memHolder = new MemoryHolder(((INativeType)this).Size);
                res._memHolder.CopyFrom(array.GetArrayAddress().Add(offset), new IntPtr(((INativeType)this).Size));
                GC.KeepAlive(array);
                return(res);
            }
예제 #3
0
            public _Array from_buffer(ArrayModule.array array, int offset = 0)
            {
                ValidateArraySizes(array, offset, ((INativeType)this).Size);

                _Array res  = (_Array)CreateInstance(Context.SharedContext);
                IntPtr addr = array.GetArrayAddress();

                res._memHolder = new MemoryHolder(addr.Add(offset), ((INativeType)this).Size);
                res._memHolder.AddObject("ffffffff", array);
                return(res);
            }
예제 #4
0
            public _Structure from_buffer(ArrayModule.array array, [DefaultParameterValue(0)] int offset)
            {
                ValidateArraySizes(array, offset, ((INativeType)this).Size);

                _Structure res  = (_Structure)CreateInstance(Context.SharedContext);
                IntPtr     addr = array.GetArrayAddress();

                res._memHolder = new MemoryHolder(addr.Add(offset), ((INativeType)this).Size);
                res._memHolder.AddObject("ffffffff", array);
                return(res);
            }
예제 #5
0
            public object from_buffer(CodeContext /*!*/ context, ArrayModule.array array, int offset = 0)
            {
                ValidateArraySizes(array, offset, ((INativeType)this).Size);

                _Union res  = (_Union)CreateInstance(context);
                IntPtr addr = array.GetArrayAddress();

                res._memHolder = new MemoryHolder(addr.Add(offset), ((INativeType)this).Size);
                res._memHolder.AddObject("ffffffff", array);
                return(res);
            }
예제 #6
0
            public _Structure from_buffer_copy(ArrayModule.array array, [DefaultParameterValue(0)] int offset)
            {
                ValidateArraySizes(array, offset, ((INativeType)this).Size);

                _Structure res = (_Structure)CreateInstance(Context.SharedContext);

                res._memHolder = new MemoryHolder(((INativeType)this).Size);
                res._memHolder.CopyFrom(array.GetArrayAddress().Add(offset), new IntPtr(((INativeType)this).Size));
                GC.KeepAlive(array);
                return(res);
            }
예제 #7
0
 public void update(object newData)
 {
     ArrayModule.array a = newData as ArrayModule.array;
     if (a != null)
     {
         update(a.ToByteArray());
     }
     else
     {
         update(Converter.ConvertToString(newData).MakeByteArray());
     }
 }
예제 #8
0
            public override BigInteger readinto(CodeContext /*!*/ context, object buf)
            {
                ByteArray bytes = buf as ByteArray;

                if (bytes != null)
                {
                    return(readinto(bytes));
                }

                ArrayModule.array array = buf as ArrayModule.array;
                if (array != null)
                {
                    return(readinto(array));
                }

                _checkClosed();
                throw PythonOps.TypeError("must be read-write buffer, not {0}", PythonTypeOps.GetName(buf));
            }
예제 #9
0
            public override BigInteger readinto(CodeContext /*!*/ context, object buf)
            {
                ByteArray bytes = buf as ByteArray;

                if (bytes != null)
                {
                    return(readinto(bytes));
                }

                ArrayModule.array arr = buf as ArrayModule.array;
                if (arr != null)
                {
                    return(readinto(bytes));
                }
                ;

                EnsureReadable();
                throw PythonOps.TypeError(
                          "argument 1 must be read/write buffer, not {0}",
                          DynamicHelpers.GetPythonType(buf).Name
                          );
            }
예제 #10
0
            public BigInteger readinto([NotNull] ArrayModule.array buffer)
            {
                _checkClosed();

                int len     = Math.Min(_length - _pos, buffer.__len__() * buffer.itemsize);
                int tailLen = len % buffer.itemsize;

                buffer.FromStream(new MemoryStream(_data, _pos, len - tailLen, false, false), 0);
                _pos += len - tailLen;

                if (tailLen != 0)
                {
                    byte[] tail = buffer.RawGetItem(len / buffer.itemsize);
                    for (int i = 0; i < tailLen; i++)
                    {
                        tail[i] = _data[_pos++];
                    }
                    buffer.FromStream(new MemoryStream(tail), len / buffer.itemsize);
                }

                return(len);
            }
예제 #11
0
 public static sha sha1(ArrayModule.array data)
 {
     return(new sha(data.ToByteArray()));
 }
예제 #12
0
 public static MD5Object md5(ArrayModule.array data)
 {
     return(new MD5Object(data));
 }
예제 #13
0
            public BigInteger readinto([NotNull] ArrayModule.array buffer)
            {
                EnsureReadable();

                return((int)buffer.FromStream(_readStream, 0, buffer.__len__() * buffer.itemsize));
            }
예제 #14
0
 private static void ValidateArraySizes(ArrayModule.array array, int offset, int size)
 {
     ValidateArraySizes(array.__len__() * array.itemsize, offset, size);
 }
예제 #15
0
 public static sha sha1(ArrayModule.array data)
 {
     return(new sha(data));
 }
예제 #16
0
 public static Sha384Object sha384(ArrayModule.array data)
 {
     return(new Sha384Object(data.ToByteArray()));
 }
예제 #17
0
파일: _sha256.cs 프로젝트: SueDou/python
 public static Sha256Object sha256(ArrayModule.array data)
 {
     return(new Sha256Object(data));
 }