Exemple #1
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual Chunk readChunk()
        {
            java.nio.ByteBuffer chunkHeadBuffer = this.readBytes(ArangoDBConstants
                                                                 .CHUNK_MIN_HEADER_SIZE);
            int  length    = chunkHeadBuffer.getInt();
            int  chunkX    = chunkHeadBuffer.getInt();
            long messageId = chunkHeadBuffer.getLong();
            long messageLength;
            int  contentLength;

            if ((1 == (chunkX & unchecked ((int)0x1))) && (chunkX >> 1 > 1))
            {
                messageLength = this.readBytes(ArangoDBConstants.LONG_BYTES).getLong
                                    ();
                contentLength = length - ArangoDBConstants.CHUNK_MAX_HEADER_SIZE;
            }
            else
            {
                messageLength = -1L;
                contentLength = length - ArangoDBConstants.CHUNK_MIN_HEADER_SIZE;
            }
            Chunk chunk = new Chunk
                              (messageId, chunkX, messageLength, 0, contentLength);

            if (LOGGER.isDebugEnabled())
            {
                LOGGER.debug(string.format("Received chunk %s:%s from message %s", chunk.getChunk
                                               (), chunk.isFirstChunk() ? 1 : 0, chunk.getMessageId()));
            }
            return(chunk);
        }
Exemple #2
0
        ///Upon return, `bb.position()` will be at the end of the message.
        /// <exception cref="System.IO.IOException"/>
        public static Capnproto.MessageReader Read(java.nio.ByteBuffer bb, Capnproto.ReaderOptions options)
        {
            bb.order(java.nio.ByteOrder.LITTLE_ENDIAN);
            int segmentCount = 1 + bb.getInt();

            if (segmentCount > 512)
            {
                throw new System.IO.IOException("too many segments");
            }
            java.nio.ByteBuffer[] segmentSlices = new java.nio.ByteBuffer[segmentCount];
            int segmentSizesBase = bb.position();
            int segmentSizesSize = segmentCount * 4;
            int align            = Capnproto.Constants.BYTES_PER_WORD - 1;
            int segmentBase      = (segmentSizesBase + segmentSizesSize + align) & ~align;
            int totalWords       = 0;

            for (int ii = 0; ii < segmentCount; ++ii)
            {
                int segmentSize = bb.getInt(segmentSizesBase + ii * 4);
                bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii] = bb.slice();
                segmentSlices[ii].limit(segmentSize * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii].order(java.nio.ByteOrder.LITTLE_ENDIAN);
                totalWords += segmentSize;
            }
            bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD);
            if (totalWords > options.traversalLimitInWords)
            {
                throw new Capnproto.DecodeException("Message size exceeds traversal limit.");
            }
            return(new Capnproto.MessageReader(segmentSlices, options));
        }
Exemple #3
0
 public override int get()
 {
     if (_position == _limit)
     {
         throw new java.nio.BufferUnderflowException();
     }
     return(byteBuffer.getInt(_position++ *libcore.io.SizeOf.INT));
 }
Exemple #4
0
        /// <exception cref="System.IO.IOException"/>
        public static Capnproto.MessageReader Read(java.nio.channels.ReadableByteChannel bc, Capnproto.ReaderOptions options)
        {
            java.nio.ByteBuffer firstWord = makeByteBuffer(Capnproto.Constants.BYTES_PER_WORD);
            fillBuffer(firstWord, bc);
            int segmentCount = 1 + firstWord.getInt(0);
            int segment0Size = 0;

            if (segmentCount > 0)
            {
                segment0Size = firstWord.getInt(4);
            }
            int totalWords = segment0Size;

            if (segmentCount > 512)
            {
                throw new System.IO.IOException("too many segments");
            }

            //In words.
            System.Collections.Generic.List <int> moreSizes = new System.Collections.Generic.List <int>();
            if (segmentCount > 1)
            {
                java.nio.ByteBuffer moreSizesRaw = makeByteBuffer(4 * (segmentCount & ~1));
                fillBuffer(moreSizesRaw, bc);
                for (int ii = 0; ii < segmentCount - 1; ++ii)
                {
                    int size = moreSizesRaw.getInt(ii * 4);
                    moreSizes.Add(size);
                    totalWords += size;
                }
            }
            if (totalWords > options.traversalLimitInWords)
            {
                throw new Capnproto.DecodeException("Message size exceeds traversal limit.");
            }
            java.nio.ByteBuffer allSegments = makeByteBuffer(totalWords * Capnproto.Constants.BYTES_PER_WORD);
            fillBuffer(allSegments, bc);
            java.nio.ByteBuffer[] segmentSlices = new java.nio.ByteBuffer[segmentCount];
            allSegments.rewind();
            segmentSlices[0] = allSegments.slice();
            segmentSlices[0].limit(segment0Size * Capnproto.Constants.BYTES_PER_WORD);
            segmentSlices[0].order(java.nio.ByteOrder.LITTLE_ENDIAN);
            int offset = segment0Size;

            for (int ii = 1; ii < segmentCount; ++ii)
            {
                allSegments.position(offset * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii] = allSegments.slice();
                segmentSlices[ii].limit(moreSizes[ii - 1] * Capnproto.Constants.BYTES_PER_WORD);
                segmentSlices[ii].order(java.nio.ByteOrder.LITTLE_ENDIAN);
                offset += moreSizes[ii - 1];
            }
            return(new Capnproto.MessageReader(segmentSlices, options));
        }
Exemple #5
0
 public RPFHeaderSection(java.nio.ByteBuffer buffer)
 {
     this.endianIndicator         = ((byte)0 != buffer.get());        // reads 1 byte, 0 for big endian
     this.headerLength            = buffer.getShort();                // reads 2 bytes
     this.filename                = NITFSUtil.getString(buffer, 12);
     this.updateIndicator         = NITFSUtil.getByteAsShort(buffer); // reads 1 byte (short)
     this.govSpecNumber           = NITFSUtil.getString(buffer, 15);
     this.govSpecDate             = NITFSUtil.getString(buffer, 8);
     this.securityClass           = NITFSUtil.getString(buffer, 1);
     this.securityCountryCode     = NITFSUtil.getString(buffer, 2);
     this.securityReleaseMark     = NITFSUtil.getString(buffer, 2);
     this.locationSectionLocation = buffer.getInt();        // read 4 bytes (int)
 }
Exemple #6
0
 /// <summary>Get unsigned int from signed int buffer</summary>
 /// <param name="intBuffer"/>
 /// <param name="index"/>
 /// <returns>long</returns>
 public static long getUnsignedInt(java.nio.ByteBuffer intBuffer, int index)
 {
     return(intBuffer.getInt(index) & unchecked ((long)(0xffffffffl)));
 }
Exemple #7
0
 /// <seealso>[Hitchens2002] p.47: Accessing Unsigned Data</seealso>
 /// <param name="buffer"/>
 /// <returns/>
 public static long getUnsignedInt(java.nio.ByteBuffer buffer)
 {
     return(buffer.getInt() & unchecked ((long)(0xffffffffl)));
 }
 public static long getUInt(java.nio.ByteBuffer buffer)
 {
     return(0xFFFFFFFFL & (long)buffer.getInt());
 }