예제 #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int read = 0, dstOffset = 0;

            for (int i = _current; i < _chunks.Count; i++)
            {
                ByteArrayChunk chunk        = _chunks[i];
                int            bytesInChunk = chunk.Count - _offset;

                if (bytesInChunk > count)
                {
                    Array.Copy(chunk.Array, chunk.Index + _offset, buffer, dstOffset, count);
                    read      += count;
                    _offset   += count;
                    _position += count;
                    return(read);
                }

                Array.Copy(chunk.Array, chunk.Index + _offset, buffer, dstOffset, bytesInChunk);

                read      += bytesInChunk;
                count     -= bytesInChunk;
                dstOffset += bytesInChunk;
                _position += bytesInChunk;

                // Allow garbage collection for the chunk, its already been read
                _chunks[_current] = null;

                _current++;
                _offset = 0;
            }
            return(read);
        }
예제 #2
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (origin == SeekOrigin.Begin)
            {
                _current  = 0;
                _offset   = 0;
                _position = 0;
            }
            if (origin == SeekOrigin.End)
            {
                _current  = _chunks.Count - 1;
                _offset   = _chunks[_current].Count - 1;
                _position = _length - 1;
            }

            _position += offset;
            if (_position < 0)
            {
                _position = 0;
            }
            else if (_position >= _length)
            {
                _position = _length - 1;
            }

            _current = 0;
            _offset  = 0;
            long remain = _position;

            for (int i = 0; i < _chunks.Count; i++)
            {
                ByteArrayChunk chunk = _chunks[i];
                if (chunk == null)
                {
                    throw new NotSupportedException("Seek not supported at this time");
                }
                if (remain > chunk.Count)
                {
                    remain -= chunk.Count;
                }
                else
                {
                    _offset = (int)remain;
                    return(_position);
                }
                _current++;
            }

            _position -= remain;
            return(_position);
        }
예제 #3
0
		public ByteArrayChunk ReadBytesToArraySegment(String name, int count)
		{
			CheckOffset(count, name);
			var segment = new ByteArrayChunk {Array = _ms.GetBuffer(), Count = count, Index = (int) _ms.Position};
			_ms.Seek(count, SeekOrigin.Current);
			return segment;
		}
예제 #4
0
		public uint Read(RawPDU raw)
		{
			uint len = raw.ReadUInt32("PDV-Length");
			_pcid = raw.ReadByte("Presentation Context ID");
			byte mch = raw.ReadByte("Message Control Header");
			_value = raw.ReadBytesToArraySegment("PDV Value", (int)len - 2);
			_command = (mch & 0x01) != 0;
			_last = (mch & 0x02) != 0;
			return len + 4;
		}
예제 #5
0
		public PDV(byte pcid, byte[] value, bool command, bool last)
		{
			_pcid = pcid;
			_value = new ByteArrayChunk { Array = value, Count = value.Length, Index = 0 };
			_command = command;
			_last = last;
		}
예제 #6
0
 public void AddChunk(ByteArrayChunk chunk)
 {
     _chunks.Add(chunk);
     _length += chunk.Count;
 }
예제 #7
0
		public void AddChunk(ByteArrayChunk chunk)
		{
			_chunks.Add(chunk);
			_length += chunk.Count;
		}