BackendMessage ParseServerMessage(NpgsqlBuffer buf, BackendMessageCode code, int len, DataRowLoadingMode dataRowLoadingMode) { switch (code) { case BackendMessageCode.RowDescription: // TODO: Recycle var rowDescriptionMessage = new RowDescriptionMessage(); return rowDescriptionMessage.Load(buf, TypeHandlerRegistry); case BackendMessageCode.DataRow: Contract.Assert(dataRowLoadingMode == DataRowLoadingMode.NonSequential || dataRowLoadingMode == DataRowLoadingMode.Sequential); return dataRowLoadingMode == DataRowLoadingMode.Sequential ? _dataRowSequentialMessage.Load(buf) : _dataRowNonSequentialMessage.Load(buf); case BackendMessageCode.CompletedResponse: return _commandCompleteMessage.Load(buf, len); case BackendMessageCode.ReadyForQuery: var rfq = _readyForQueryMessage.Load(buf); TransactionStatus = rfq.TransactionStatusIndicator; return rfq; case BackendMessageCode.EmptyQueryResponse: return EmptyQueryMessage.Instance; case BackendMessageCode.ParseComplete: return ParseCompleteMessage.Instance; case BackendMessageCode.ParameterDescription: return _parameterDescriptionMessage.Load(buf); case BackendMessageCode.BindComplete: return BindCompleteMessage.Instance; case BackendMessageCode.NoData: return NoDataMessage.Instance; case BackendMessageCode.CloseComplete: return CloseCompletedMessage.Instance; case BackendMessageCode.ParameterStatus: HandleParameterStatus(buf.ReadNullTerminatedString(), buf.ReadNullTerminatedString()); return null; case BackendMessageCode.NoticeResponse: // TODO: Recycle FireNotice(new NpgsqlError(buf)); return null; case BackendMessageCode.NotificationResponse: FireNotification(new NpgsqlNotificationEventArgs(buf)); return null; case BackendMessageCode.AuthenticationRequest: var authType = (AuthenticationRequestType)buf.ReadInt32(); _log.Trace("Received AuthenticationRequest of type " + authType); switch (authType) { case AuthenticationRequestType.AuthenticationOk: return AuthenticationOkMessage.Instance; case AuthenticationRequestType.AuthenticationCleartextPassword: return AuthenticationCleartextPasswordMessage.Instance; case AuthenticationRequestType.AuthenticationMD5Password: return AuthenticationMD5PasswordMessage.Load(buf); case AuthenticationRequestType.AuthenticationGSS: return AuthenticationGSSMessage.Instance; case AuthenticationRequestType.AuthenticationSSPI: return AuthenticationSSPIMessage.Instance; case AuthenticationRequestType.AuthenticationGSSContinue: return AuthenticationGSSContinueMessage.Load(buf, len); default: throw new NotSupportedException(String.Format(L10N.AuthenticationMethodNotSupported, authType)); } case BackendMessageCode.BackendKeyData: BackendProcessId = buf.ReadInt32(); BackendSecretKey = buf.ReadInt32(); return null; case BackendMessageCode.CopyData: case BackendMessageCode.CopyDone: case BackendMessageCode.CancelRequest: case BackendMessageCode.CopyDataRows: case BackendMessageCode.CopyInResponse: case BackendMessageCode.CopyOutResponse: throw new NotImplementedException(); case BackendMessageCode.PortalSuspended: case BackendMessageCode.IO_ERROR: Debug.Fail("Unimplemented message: " + code); throw new NotImplementedException("Unimplemented message: " + code); case BackendMessageCode.ErrorResponse: return null; case BackendMessageCode.FunctionCallResponse: // We don't use the obsolete function call protocol throw new Exception("Unexpected backend message: " + code); default: throw PGUtil.ThrowIfReached("Unknown backend message code: " + code); } }
internal NpgsqlError(NpgsqlBuffer buf) : this() { while (true) { var code = (ErrorFieldTypeCode)buf.ReadByte(); switch (code) { case ErrorFieldTypeCode.Done: // Null terminator; error message fully consumed. return; case ErrorFieldTypeCode.Severity: Severity = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Code: Code = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Message: Message = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Detail: Detail = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Hint: Hint = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Position: Position = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.InternalPosition: InternalPosition = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.InternalQuery: InternalQuery = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Where: Where = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.File: File = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Line: Line = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.Routine: Routine = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.SchemaName: SchemaName = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.TableName: TableName = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.ColumnName: ColumnName = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.DataTypeName: DataTypeName = buf.ReadNullTerminatedString(); break; case ErrorFieldTypeCode.ConstraintName: ConstraintName = buf.ReadNullTerminatedString(); break; default: // Unknown error field; consume and discard. buf.ReadNullTerminatedString(); break; } } }
internal NpgsqlNotificationEventArgs(NpgsqlBuffer buf) { PID = buf.ReadInt32(); Condition = buf.ReadNullTerminatedString(); AdditionalInformation = buf.ReadNullTerminatedString(); }