public override bool Receive(int len) { var headDelta = 0; if (!HeadRecv) { HeadRecv = true; if (BufferLen < Config.GramSize) { return(false); } Gram = ProtoGram.FromByteArray(Buffer); headDelta = Gram.Size; } if (RecvStream == null) { switch (Gram.Command) { case ProtoCommand.List: case ProtoCommand.Head: RecvStream = new MemoryStream(); break; case ProtoCommand.Get: RecvStream = Fs.Put(FileName); break; default: throw new ArgumentOutOfRangeException(); } } RecvStream?.Write(Buffer, headDelta, len - headDelta); return(true); }
public override bool Receive(int len) { BufferLen += len; if (BufferLen < Config.GramSize) { return(false); } Gram = ProtoGram.FromByteArray(Buffer); if (RecvStream != null) { return(false); } switch (Gram.Command) { case ProtoCommand.Get: RecvStream = Fs.Get(Url, Gram.Start, Gram.Length); break; case ProtoCommand.List: var list = Fs.List(Url); RecvStream = list.SerializeStream(); break; case ProtoCommand.Head: var head = Fs.Head(Url); RecvStream = head.SerializeStream(); break; default: throw new ArgumentOutOfRangeException(); } FileLength = this.Gram.Length != 0 ? this.Gram.Length : RecvStream.Length - Gram.Start; return(true); }