Exemple #1
0
        public Bytes tobytes()
        {
            CheckBuffer();
            if (_matchesBuffer && _step == 1)
            {
                return(_buffer.ToBytes(_start / _itemsize, _end / _itemsize));
            }

            byte[] bytes = getByteRange(_start, numberOfElements() * _itemsize);

            if (_step == 1)
            {
                return(Bytes.Make(bytes));
            }

            // getByteRange() doesn't care about our _step, so if we have one
            // that isn't 1, we will need to get rid of any bytes we don't care
            // about and potentially adjust for a reversed memoryview.
            byte[] stridedBytes = new byte[bytes.Length / _itemsize];
            for (int indexStrided = 0; indexStrided < stridedBytes.Length; indexStrided += _itemsize)
            {
                int indexInBytes = indexStrided * _step;

                for (int j = 0; j < _itemsize; j++)
                {
                    stridedBytes[indexStrided + j] = bytes[indexInBytes + j];
                }
            }

            return(Bytes.Make(stridedBytes));
        }
Exemple #2
0
        public static bool _compare_digest(object a, object b)
        {
            if (a is string && b is string)
            {
                string aStr = a as string;
                string bStr = b as string;
                return(CompareBytes(aStr.MakeByteArray(), bStr.MakeByteArray()));
            }
            else if (a is IBufferProtocol && b is IBufferProtocol)
            {
                IBufferProtocol aBuf = a as IBufferProtocol;
                IBufferProtocol bBuf = b as IBufferProtocol;
                if (aBuf.NumberDimensions > 1 || bBuf.NumberDimensions > 1)
                {
                    throw PythonOps.BufferError("Buffer must be single dimension");
                }

                return(CompareBytes(aBuf.ToBytes(0, null), bBuf.ToBytes(0, null)));
            }
            throw PythonOps.TypeError("unsupported operand types(s) or combination of types: '{0}' and '{1}", PythonOps.GetPythonTypeName(a), PythonOps.GetPythonTypeName(b));
        }
Exemple #3
0
 public Bytes tobytes()
 {
     CheckBuffer();
     return(_buffer.ToBytes(_start, _end));
 }
 public Bytes tobytes()
 {
     return(_buffer.ToBytes(_start, _end));
 }
Exemple #5
0
 public static Bytes a2b_uu(CodeContext /*!*/ context, [NotNull] IBufferProtocol data)
 => a2b_uu_impl(context, data.ToBytes());