public static void ReadHead(Stream stream, Bcp.ReadState readState, BcpDelegate.ProcessReadHead processReadHead, BcpDelegate.ExceptionHandler exceptionHandler) { var sessionId = new byte[Bcp.NumBytesSessionId]; ProcessReadAll processReadAll = delegate() { ProcessReadVarint processReadIsRenew = delegate(uint isRenew) { ProcessReadVarint processReadConnectionId = delegate(uint connectionId) { readState.Cancel(); processReadHead(new Bcp.ConnectionHead(sessionId, Convert.ToBoolean(isRenew), connectionId)); }; ReadUnsignedVarint(stream, readState, processReadConnectionId, exceptionHandler); }; ReadUnsignedVarint(stream, readState, processReadIsRenew, exceptionHandler); }; ReadAll(stream, readState, sessionId, 0, Bcp.NumBytesSessionId, processReadAll, exceptionHandler); }