Ejemplo n.º 1
0
        public static uint ReadBufferUInt32(byte[] buffer, int bufferOffset)
        {
            var uintBuffer = new byte[4];

            Buffer.BlockCopy(buffer, bufferOffset, uintBuffer, 0, 4);
            return(LittleEndianByteOrder.GetUInt32(uintBuffer));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Expect the upcoming 4 bytes are int32, read it and return it;
        /// </summary>
        public static uint ExpectUInt32(this Stream target)
        {
            var buff = new byte[4];

            if (target.Read(buff) == 4)
            {
                return(LittleEndianByteOrder.GetUInt32(buff));
            }
            else
            {
                throw new EndOfStreamException();
            }
        }
Ejemplo n.º 3
0
        uint ReadUInt32FromTrailingContent(IBlock block)
        {
            var buffer        = new byte[4];
            var contentLength = block.GetHeader(kBlockContentLength);

            if ((contentLength % 4) != 0)
            {
                throw new DataMisalignedException("Block content length not %4: " + contentLength);
            }

            if (contentLength == 0)
            {
                throw new InvalidDataException("Trying to dequeue UInt32 from an empty block");
            }

            block.Read(dst: buffer, dstOffset: 0, srcOffset: (int)contentLength - 4, count: 4);
            return(LittleEndianByteOrder.GetUInt32(buffer));
        }