コード例 #1
0
ファイル: Buffer.cs プロジェクト: slagusev/api
 private static void OutputBuffer(ByteBuffer byteBuffer, Array dst, Type dstType, int dstStartIndex, int dstIndexLength)
 {
     if (dstType == typeof(bool))
     {
         for (var i = 0; i < dstIndexLength; i++)
         {
             dst[dstStartIndex + i] = byteBuffer.Get(i) == 1;
         }
     }
     else if (dstType == typeof(byte))
     {
         //nothing to do, the dst array is wrapped already.
     }
     else if (dstType == typeof(char))
     {
         var charBuffer = byteBuffer.AsCharBuffer();
         charBuffer.Get((char[])dst, dstStartIndex, dstIndexLength);
     }
     else if (dstType == typeof(short))
     {
         var shortBuffer = byteBuffer.AsShortBuffer();
         shortBuffer.Get((short[])dst, dstStartIndex, dstIndexLength);
     }
     else if (dstType == typeof(float))
     {
         var floatBuffer = byteBuffer.AsFloatBuffer();
         floatBuffer.Get((float[])dst, dstStartIndex, dstIndexLength);
     }
     else if (dstType == typeof(int))
     {
         var intBuffer = byteBuffer.AsIntBuffer();
         intBuffer.Get((int[])dst, dstStartIndex, dstIndexLength);
     }
     else if (dstType == typeof(double))
     {
         var doubleBuffer = byteBuffer.AsDoubleBuffer();
         doubleBuffer.Get((double[])dst, dstStartIndex, dstIndexLength);
     }
     else if (dstType == typeof(long))
     {
         var longBuffer = byteBuffer.AsLongBuffer();
         longBuffer.Get((long[])dst, dstStartIndex, dstIndexLength);
     }
     else
     {
         throw new NotImplementedException("System.Buffer.OutputBuffer");
     }
 }
コード例 #2
0
ファイル: Buffer.cs プロジェクト: slagusev/api
        private static ByteBuffer CreateByteBuffer(Array src, Type srcType, int srcStartIndex, int srcIndexLength, Array dst, Type dstType, int dstStartIndex, int dstIndexLength)
        {
            ByteBuffer buffer = null;

            if (dstType == typeof(byte))
            {
                buffer = ByteBuffer.Wrap((byte[])dst, dstStartIndex, dstIndexLength);
            }
            else if (srcType == typeof(byte))
            {
                buffer = ByteBuffer.Wrap((byte[])src, srcStartIndex, srcIndexLength);
            }
            else
            {
                var numberOfBytes = src.Length * NumberOfBytesForPrimitiveType(srcType);
                buffer = ByteBuffer.Allocate(numberOfBytes);
            }

            buffer.Order(ByteOrder.NativeOrder());

            if (srcType == typeof(byte))
            {
                if (dstType == typeof(byte))
                {
                    //both source and dest are bytes, we wrapped the dest, so copy the source into it (for as many bytes as needed).
                    buffer.Put((byte[])src, srcStartIndex, srcIndexLength);
                }
            }
            else if (srcType == typeof(bool))
            {
                for (var i = 0; i < srcIndexLength; i++)
                {
                    if ((bool)src[srcStartIndex + i])
                    {
                        buffer.Put((byte)1);
                    }
                    else
                    {
                        buffer.Put((byte)0);
                    }
                }
            }
            else if (srcType == typeof(char))
            {
                var charBuffer = buffer.AsCharBuffer();
                charBuffer.Put((char[])src, srcStartIndex, srcIndexLength);
            }
            else if (srcType == typeof(short))
            {
                var shortBuffer = buffer.AsShortBuffer();
                shortBuffer.Put((short[])src, srcStartIndex, srcIndexLength);
            }
            else if (srcType == typeof(float))
            {
                var floatBuffer = buffer.AsFloatBuffer();
                floatBuffer.Put((float[])src, srcStartIndex, srcIndexLength);
            }
            else if (srcType == typeof(int))
            {
                var intBuffer = buffer.AsIntBuffer();
                intBuffer.Put((int[])src, srcStartIndex, srcIndexLength);
            }
            else if (srcType == typeof(double))
            {
                var doubleBuffer = buffer.AsDoubleBuffer();
                doubleBuffer.Put((double[])src, srcStartIndex, srcIndexLength);
            }
            else if (srcType == typeof(long))
            {
                var longBuffer = buffer.AsLongBuffer();
                longBuffer.Put((long[])src, srcStartIndex, srcIndexLength);
            }
            else
            {
                throw new NotImplementedException("System.Buffer.CreateByteBuffer");
            }

            return(buffer);
        }
コード例 #3
0
        private static void testViews(int level, ByteBuffer b, bool direct)
        {
            //ShortBuffer sb = b.asShortBuffer();
            //BasicShort.test(level, sb, direct);
            //checkBytes(b, new byte[] { 0, (byte)ic(0) });
            //checkInvalidMarkException(sb);

            //CharBuffer cb = b.asCharBuffer();
            //BasicChar.test(level, cb, direct);
            //checkBytes(b, new byte[] { 0, (byte)ic(0) });
            //checkInvalidMarkException(cb);

            //IntBuffer ib = b.asIntBuffer();
            //BasicInt.test(level, ib, direct);
            //checkBytes(b, new byte[] { 0, 0, 0, (byte)ic(0) });
            //checkInvalidMarkException(ib);

            LongBuffer lb = b.AsLongBuffer();
            TestLongBuffer.test(level, lb, direct);
            checkBytes(b, new byte[] { 0, 0, 0, 0, 0, 0, 0, (byte)Ic(0) });
            checkInvalidMarkException(lb);

            //FloatBuffer fb = b.asFloatBuffer();
            //BasicFloat.test(level, fb, direct);
            //checkBytes(b, new byte[] { 0x42, (byte)0xc2, 0, 0 });
            //checkInvalidMarkException(fb);

            //DoubleBuffer db = b.asDoubleBuffer();
            //BasicDouble.test(level, db, direct);
            //checkBytes(b, new byte[] { 0x40, 0x58, 0x40, 0, 0, 0, 0, 0 });
            //checkInvalidMarkException(db);
        }