void WriterNodeMove() { if (Node.Next == null) //next block is null { if (ByteBlockBuffer.LinkedList.First != ByteBlockBuffer.Reader.Node) //give priority to reuse block from beginning { Node = ByteBlockBuffer.LinkedList.First; } else //create new block { ByteBlockBuffer.LinkedList.AddAfter(Node, ByteBlockBuffer.CreateBlock()); Node = Node.Next; } } else //next block is exist { if (Node.Next == ByteBlockBuffer.Reader.Node) //all blocks are occupied, create a new one { ByteBlockBuffer.LinkedList.AddAfter(Node, ByteBlockBuffer.CreateBlock()); Node = Node.Next; } else //reuse block { Node = Node.Next; } } }
/// <summary> /// how many bytes you have read out /// used to move postion /// </summary> /// <param name="length"></param> public void MovePosition(int length) { Position += length; if (Position > ByteBlockBuffer.Size) { throw new Exception("Reader position error"); } if (ByteBlockBuffer.IsReaderAndWriterInSameNode()) { if (Position > ByteBlockBuffer.Writer.Position) { throw new Exception("When in same node, Reader's position must not large than Writer's postion"); } } if (Position == ByteBlockBuffer.Size) //current block have already read finish { Position = 0; ReaderNodeMove(); } }
public ReadOperator(ByteBlockBuffer byteBlockBuffer) : base(byteBlockBuffer) { }
public ByteBlockOperator(ByteBlockBuffer byteBlockBuffer) { ByteBlockBuffer = byteBlockBuffer; Node = ByteBlockBuffer.LinkedList.First; }
public WriteOperator(ByteBlockBuffer byteBlockBuffer) : base(byteBlockBuffer) { }