1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
use types::RDKafkaRespErr;
use types::RDKafkaRespErr::*;
use types::RDKafkaError;
use types::RDKafkaError::*;

/// This is not great. For legacy reasons some usage of rd_kafka_resp_err_t is
/// passed as an integer in some places. There seems to be no easy way in Rust to
/// match this the other way around so we do it manually.
pub fn primitive_to_rd_kafka_resp_err_t(error: i32) -> Option<RDKafkaRespErr> {
    match error {
        -200 => Some(RD_KAFKA_RESP_ERR__BEGIN),
        -199 => Some(RD_KAFKA_RESP_ERR__BAD_MSG),
        -198 => Some(RD_KAFKA_RESP_ERR__BAD_COMPRESSION),
        -197 => Some(RD_KAFKA_RESP_ERR__DESTROY),
        -196 => Some(RD_KAFKA_RESP_ERR__FAIL),
        -195 => Some(RD_KAFKA_RESP_ERR__TRANSPORT),
        -194 => Some(RD_KAFKA_RESP_ERR__CRIT_SYS_RESOURCE),
        -193 => Some(RD_KAFKA_RESP_ERR__RESOLVE),
        -192 => Some(RD_KAFKA_RESP_ERR__MSG_TIMED_OUT),
        -191 => Some(RD_KAFKA_RESP_ERR__PARTITION_EOF),
        -190 => Some(RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION),
        -189 => Some(RD_KAFKA_RESP_ERR__FS),
        -188 => Some(RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC),
        -187 => Some(RD_KAFKA_RESP_ERR__ALL_BROKERS_DOWN),
        -186 => Some(RD_KAFKA_RESP_ERR__INVALID_ARG),
        -185 => Some(RD_KAFKA_RESP_ERR__TIMED_OUT),
        -184 => Some(RD_KAFKA_RESP_ERR__QUEUE_FULL),
        -183 => Some(RD_KAFKA_RESP_ERR__ISR_INSUFF),
        -182 => Some(RD_KAFKA_RESP_ERR__NODE_UPDATE),
        -181 => Some(RD_KAFKA_RESP_ERR__SSL),
        -180 => Some(RD_KAFKA_RESP_ERR__WAIT_COORD),
        -179 => Some(RD_KAFKA_RESP_ERR__UNKNOWN_GROUP),
        -178 => Some(RD_KAFKA_RESP_ERR__IN_PROGRESS),
        -177 => Some(RD_KAFKA_RESP_ERR__PREV_IN_PROGRESS),
        -176 => Some(RD_KAFKA_RESP_ERR__EXISTING_SUBSCRIPTION),
        -175 => Some(RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS),
        -174 => Some(RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS),
        -173 => Some(RD_KAFKA_RESP_ERR__CONFLICT),
        -172 => Some(RD_KAFKA_RESP_ERR__STATE),
        -171 => Some(RD_KAFKA_RESP_ERR__UNKNOWN_PROTOCOL),
        -170 => Some(RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED),
        -169 => Some(RD_KAFKA_RESP_ERR__AUTHENTICATION),
        -168 => Some(RD_KAFKA_RESP_ERR__NO_OFFSET),
        -167 => Some(RD_KAFKA_RESP_ERR__OUTDATED),
        -166 => Some(RD_KAFKA_RESP_ERR__TIMED_OUT_QUEUE),
        -165 => Some(RD_KAFKA_RESP_ERR__UNSUPPORTED_FEATURE),
        -164 => Some(RD_KAFKA_RESP_ERR__WAIT_CACHE),
        -163 => Some(RD_KAFKA_RESP_ERR__INTR),
        -162 => Some(RD_KAFKA_RESP_ERR__KEY_SERIALIZATION),
        -161 => Some(RD_KAFKA_RESP_ERR__VALUE_SERIALIZATION),
        -160 => Some(RD_KAFKA_RESP_ERR__KEY_DESERIALIZATION),
        -159 => Some(RD_KAFKA_RESP_ERR__VALUE_DESERIALIZATION),
        -158 => Some(RD_KAFKA_RESP_ERR__PARTIAL),
        -157 => Some(RD_KAFKA_RESP_ERR__READ_ONLY),
        -156 => Some(RD_KAFKA_RESP_ERR__NOENT),
        -155 => Some(RD_KAFKA_RESP_ERR__UNDERFLOW),
        -154 => Some(RD_KAFKA_RESP_ERR__INVALID_TYPE),
        -153 => Some(RD_KAFKA_RESP_ERR__RETRY),
        -152 => Some(RD_KAFKA_RESP_ERR__PURGE_QUEUE),
        -151 => Some(RD_KAFKA_RESP_ERR__PURGE_INFLIGHT),
        -150 => Some(RD_KAFKA_RESP_ERR__FATAL),
        -149 => Some(RD_KAFKA_RESP_ERR__INCONSISTENT),
        -148 => Some(RD_KAFKA_RESP_ERR__GAPLESS_GUARANTEE),
        -147 => Some(RD_KAFKA_RESP_ERR__MAX_POLL_EXCEEDED),
        -100 => Some(RD_KAFKA_RESP_ERR__END),
        -1   => Some(RD_KAFKA_RESP_ERR_UNKNOWN),
        0    => Some(RD_KAFKA_RESP_ERR_NO_ERROR),
        1    => Some(RD_KAFKA_RESP_ERR_OFFSET_OUT_OF_RANGE),
        2    => Some(RD_KAFKA_RESP_ERR_INVALID_MSG),
        3    => Some(RD_KAFKA_RESP_ERR_UNKNOWN_TOPIC_OR_PART),
        4    => Some(RD_KAFKA_RESP_ERR_INVALID_MSG_SIZE),
        5    => Some(RD_KAFKA_RESP_ERR_LEADER_NOT_AVAILABLE),
        6    => Some(RD_KAFKA_RESP_ERR_NOT_LEADER_FOR_PARTITION),
        7    => Some(RD_KAFKA_RESP_ERR_REQUEST_TIMED_OUT),
        8    => Some(RD_KAFKA_RESP_ERR_BROKER_NOT_AVAILABLE),
        9    => Some(RD_KAFKA_RESP_ERR_REPLICA_NOT_AVAILABLE),
        10   => Some(RD_KAFKA_RESP_ERR_MSG_SIZE_TOO_LARGE),
        11   => Some(RD_KAFKA_RESP_ERR_STALE_CTRL_EPOCH),
        12   => Some(RD_KAFKA_RESP_ERR_OFFSET_METADATA_TOO_LARGE),
        13   => Some(RD_KAFKA_RESP_ERR_NETWORK_EXCEPTION),
        14   => Some(RD_KAFKA_RESP_ERR_GROUP_LOAD_IN_PROGRESS),
        15   => Some(RD_KAFKA_RESP_ERR_GROUP_COORDINATOR_NOT_AVAILABLE),
        16   => Some(RD_KAFKA_RESP_ERR_NOT_COORDINATOR_FOR_GROUP),
        17   => Some(RD_KAFKA_RESP_ERR_TOPIC_EXCEPTION),
        18   => Some(RD_KAFKA_RESP_ERR_RECORD_LIST_TOO_LARGE),
        19   => Some(RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS),
        20   => Some(RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS_AFTER_APPEND),
        21   => Some(RD_KAFKA_RESP_ERR_INVALID_REQUIRED_ACKS),
        22   => Some(RD_KAFKA_RESP_ERR_ILLEGAL_GENERATION),
        23   => Some(RD_KAFKA_RESP_ERR_INCONSISTENT_GROUP_PROTOCOL),
        24   => Some(RD_KAFKA_RESP_ERR_INVALID_GROUP_ID),
        25   => Some(RD_KAFKA_RESP_ERR_UNKNOWN_MEMBER_ID),
        26   => Some(RD_KAFKA_RESP_ERR_INVALID_SESSION_TIMEOUT),
        27   => Some(RD_KAFKA_RESP_ERR_REBALANCE_IN_PROGRESS),
        28   => Some(RD_KAFKA_RESP_ERR_INVALID_COMMIT_OFFSET_SIZE),
        29   => Some(RD_KAFKA_RESP_ERR_TOPIC_AUTHORIZATION_FAILED),
        30   => Some(RD_KAFKA_RESP_ERR_GROUP_AUTHORIZATION_FAILED),
        31   => Some(RD_KAFKA_RESP_ERR_CLUSTER_AUTHORIZATION_FAILED),
        32   => Some(RD_KAFKA_RESP_ERR_INVALID_TIMESTAMP),
        33   => Some(RD_KAFKA_RESP_ERR_UNSUPPORTED_SASL_MECHANISM),
        34   => Some(RD_KAFKA_RESP_ERR_ILLEGAL_SASL_STATE),
        35   => Some(RD_KAFKA_RESP_ERR_UNSUPPORTED_VERSION),
        36   => Some(RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS),
        37   => Some(RD_KAFKA_RESP_ERR_INVALID_PARTITIONS),
        38   => Some(RD_KAFKA_RESP_ERR_INVALID_REPLICATION_FACTOR),
        39   => Some(RD_KAFKA_RESP_ERR_INVALID_REPLICA_ASSIGNMENT),
        40   => Some(RD_KAFKA_RESP_ERR_INVALID_CONFIG),
        41   => Some(RD_KAFKA_RESP_ERR_NOT_CONTROLLER),
        42   => Some(RD_KAFKA_RESP_ERR_INVALID_REQUEST),
        43   => Some(RD_KAFKA_RESP_ERR_UNSUPPORTED_FOR_MESSAGE_FORMAT),
        44   => Some(RD_KAFKA_RESP_ERR_POLICY_VIOLATION),
        45   => Some(RD_KAFKA_RESP_ERR_OUT_OF_ORDER_SEQUENCE_NUMBER),
        46   => Some(RD_KAFKA_RESP_ERR_DUPLICATE_SEQUENCE_NUMBER),
        47   => Some(RD_KAFKA_RESP_ERR_INVALID_PRODUCER_EPOCH),
        48   => Some(RD_KAFKA_RESP_ERR_INVALID_TXN_STATE),
        49   => Some(RD_KAFKA_RESP_ERR_INVALID_PRODUCER_ID_MAPPING),
        50   => Some(RD_KAFKA_RESP_ERR_INVALID_TRANSACTION_TIMEOUT),
        51   => Some(RD_KAFKA_RESP_ERR_CONCURRENT_TRANSACTIONS),
        52   => Some(RD_KAFKA_RESP_ERR_TRANSACTION_COORDINATOR_FENCED),
        53   => Some(RD_KAFKA_RESP_ERR_TRANSACTIONAL_ID_AUTHORIZATION_FAILED),
        54   => Some(RD_KAFKA_RESP_ERR_SECURITY_DISABLED),
        55   => Some(RD_KAFKA_RESP_ERR_OPERATION_NOT_ATTEMPTED),
        56   => Some(RD_KAFKA_RESP_ERR_KAFKA_STORAGE_ERROR),
        57   => Some(RD_KAFKA_RESP_ERR_LOG_DIR_NOT_FOUND),
        58   => Some(RD_KAFKA_RESP_ERR_SASL_AUTHENTICATION_FAILED),
        59   => Some(RD_KAFKA_RESP_ERR_UNKNOWN_PRODUCER_ID),
        60   => Some(RD_KAFKA_RESP_ERR_REASSIGNMENT_IN_PROGRESS),
        61   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_AUTH_DISABLED),
        62   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_NOT_FOUND),
        63   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_OWNER_MISMATCH),
        64   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_REQUEST_NOT_ALLOWED),
        65   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_AUTHORIZATION_FAILED),
        66   => Some(RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_EXPIRED),
        67   => Some(RD_KAFKA_RESP_ERR_INVALID_PRINCIPAL_TYPE),
        68   => Some(RD_KAFKA_RESP_ERR_NON_EMPTY_GROUP),
        69   => Some(RD_KAFKA_RESP_ERR_GROUP_ID_NOT_FOUND),
        70   => Some(RD_KAFKA_RESP_ERR_FETCH_SESSION_ID_NOT_FOUND),
        71   => Some(RD_KAFKA_RESP_ERR_INVALID_FETCH_SESSION_EPOCH),
        72   => Some(RD_KAFKA_RESP_ERR_LISTENER_NOT_FOUND),
        73   => Some(RD_KAFKA_RESP_ERR_TOPIC_DELETION_DISABLED),
        74   => Some(RD_KAFKA_RESP_ERR_UNSUPPORTED_COMPRESSION_TYPE),
        // END ALL
        75   => Some(RD_KAFKA_RESP_ERR_END_ALL),
        _ => None
    }
}

pub fn rd_kafka_resp_err_t_to_rdkafka_error(err: RDKafkaRespErr) -> RDKafkaError {
    match err {
        RD_KAFKA_RESP_ERR__BEGIN => Begin,
        RD_KAFKA_RESP_ERR__BAD_MSG => BadMessage,
        RD_KAFKA_RESP_ERR__BAD_COMPRESSION => BadCompression,
        RD_KAFKA_RESP_ERR__DESTROY => BrokerDestroy,
        RD_KAFKA_RESP_ERR__FAIL => Fail,
        RD_KAFKA_RESP_ERR__TRANSPORT => BrokerTransportFailure,
        RD_KAFKA_RESP_ERR__CRIT_SYS_RESOURCE => CriticalSystemResource,
        RD_KAFKA_RESP_ERR__RESOLVE => Resolve,
        RD_KAFKA_RESP_ERR__MSG_TIMED_OUT => MessageTimedOut,
        RD_KAFKA_RESP_ERR__PARTITION_EOF => PartitionEOF,
        RD_KAFKA_RESP_ERR__UNKNOWN_PARTITION => UnknownPartition,
        RD_KAFKA_RESP_ERR__FS => FileSystem,
        RD_KAFKA_RESP_ERR__UNKNOWN_TOPIC => UnknownTopic,
        RD_KAFKA_RESP_ERR__ALL_BROKERS_DOWN => AllBrokersDown,
        RD_KAFKA_RESP_ERR__INVALID_ARG => InvalidArgument,
        RD_KAFKA_RESP_ERR__TIMED_OUT => OperationTimedOut,
        RD_KAFKA_RESP_ERR__QUEUE_FULL => QueueFull,
        RD_KAFKA_RESP_ERR__ISR_INSUFF => ISRInsufficient,
        RD_KAFKA_RESP_ERR__NODE_UPDATE => NodeUpdate,
        RD_KAFKA_RESP_ERR__SSL => SSL,
        RD_KAFKA_RESP_ERR__WAIT_COORD => WaitingForCoordinator,
        RD_KAFKA_RESP_ERR__UNKNOWN_GROUP => UnknownGroup,
        RD_KAFKA_RESP_ERR__IN_PROGRESS => InProgress,
        RD_KAFKA_RESP_ERR__PREV_IN_PROGRESS => PreviousInProgress,
        RD_KAFKA_RESP_ERR__EXISTING_SUBSCRIPTION => ExistingSubscription,
        RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS => AssignPartitions,
        RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS => RevokePartitions,
        RD_KAFKA_RESP_ERR__CONFLICT => Conflict,
        RD_KAFKA_RESP_ERR__STATE => State,
        RD_KAFKA_RESP_ERR__UNKNOWN_PROTOCOL => UnknownProtocol,
        RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED => NotImplemented,
        RD_KAFKA_RESP_ERR__AUTHENTICATION => Authentication,
        RD_KAFKA_RESP_ERR__NO_OFFSET => NoOffset,
        RD_KAFKA_RESP_ERR__OUTDATED => Outdated,
        RD_KAFKA_RESP_ERR__TIMED_OUT_QUEUE => TimedOutQueue,
        RD_KAFKA_RESP_ERR__UNSUPPORTED_FEATURE => UnsupportedFeature,
        RD_KAFKA_RESP_ERR__WAIT_CACHE => WaitCache,
        RD_KAFKA_RESP_ERR__INTR => Interrupted,
        RD_KAFKA_RESP_ERR__KEY_SERIALIZATION => KeySerialization,
        RD_KAFKA_RESP_ERR__VALUE_SERIALIZATION => ValueSerialization,
        RD_KAFKA_RESP_ERR__KEY_DESERIALIZATION => KeyDeserialization,
        RD_KAFKA_RESP_ERR__VALUE_DESERIALIZATION => ValueDeserialization,
        RD_KAFKA_RESP_ERR__PARTIAL => Partial,
        RD_KAFKA_RESP_ERR__READ_ONLY => ReadOnly,
        RD_KAFKA_RESP_ERR__NOENT => NoEnt,
        RD_KAFKA_RESP_ERR__UNDERFLOW => Underflow,
        RD_KAFKA_RESP_ERR__INVALID_TYPE => InvalidType,
        RD_KAFKA_RESP_ERR__RETRY => Retry,
        RD_KAFKA_RESP_ERR__PURGE_QUEUE => PurgeQueue,
        RD_KAFKA_RESP_ERR__PURGE_INFLIGHT => PurgeInflight,
        RD_KAFKA_RESP_ERR__FATAL => Fatal,
        RD_KAFKA_RESP_ERR__INCONSISTENT => Inconsistent,
        RD_KAFKA_RESP_ERR__GAPLESS_GUARANTEE => GaplessGuarantee,
        RD_KAFKA_RESP_ERR__MAX_POLL_EXCEEDED => PollExceeded,
        RD_KAFKA_RESP_ERR__END => End,
        RD_KAFKA_RESP_ERR_UNKNOWN => Unknown,
        RD_KAFKA_RESP_ERR_NO_ERROR => NoError,
        RD_KAFKA_RESP_ERR_OFFSET_OUT_OF_RANGE => OffsetOutOfRange,
        RD_KAFKA_RESP_ERR_INVALID_MSG => InvalidMessage,
        RD_KAFKA_RESP_ERR_UNKNOWN_TOPIC_OR_PART => UnknownTopicOrPartition,
        RD_KAFKA_RESP_ERR_INVALID_MSG_SIZE => InvalidMessageSize,
        RD_KAFKA_RESP_ERR_LEADER_NOT_AVAILABLE => LeaderNotAvailable,
        RD_KAFKA_RESP_ERR_NOT_LEADER_FOR_PARTITION => NotLeaderForPartition,
        RD_KAFKA_RESP_ERR_REQUEST_TIMED_OUT => RequestTimedOut,
        RD_KAFKA_RESP_ERR_BROKER_NOT_AVAILABLE => BrokerNotAvailable,
        RD_KAFKA_RESP_ERR_REPLICA_NOT_AVAILABLE => ReplicaNotAvailable,
        RD_KAFKA_RESP_ERR_MSG_SIZE_TOO_LARGE => MessageSizeTooLarge,
        RD_KAFKA_RESP_ERR_STALE_CTRL_EPOCH => StaleControllerEpoch,
        RD_KAFKA_RESP_ERR_OFFSET_METADATA_TOO_LARGE => OffsetMetadataTooLarge,
        RD_KAFKA_RESP_ERR_NETWORK_EXCEPTION => NetworkException,
        RD_KAFKA_RESP_ERR_GROUP_LOAD_IN_PROGRESS => GroupLoadInProgress,
        RD_KAFKA_RESP_ERR_GROUP_COORDINATOR_NOT_AVAILABLE => GroupCoordinatorNotAvailable,
        RD_KAFKA_RESP_ERR_NOT_COORDINATOR_FOR_GROUP => NotCoordinatorForGroup,
        RD_KAFKA_RESP_ERR_TOPIC_EXCEPTION => InvalidTopic,
        RD_KAFKA_RESP_ERR_RECORD_LIST_TOO_LARGE => MessageBatchTooLarge,
        RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS => NotEnoughReplicas,
        RD_KAFKA_RESP_ERR_NOT_ENOUGH_REPLICAS_AFTER_APPEND => NotEnoughReplicasAfterAppend,
        RD_KAFKA_RESP_ERR_INVALID_REQUIRED_ACKS => InvalidRequiredAcks,
        RD_KAFKA_RESP_ERR_ILLEGAL_GENERATION => IllegalGeneration,
        RD_KAFKA_RESP_ERR_INCONSISTENT_GROUP_PROTOCOL => InconsistentGroupProtocol,
        RD_KAFKA_RESP_ERR_INVALID_GROUP_ID => InvalidGroupId,
        RD_KAFKA_RESP_ERR_UNKNOWN_MEMBER_ID => UnknownMemberId,
        RD_KAFKA_RESP_ERR_INVALID_SESSION_TIMEOUT => InvalidSessionTimeout,
        RD_KAFKA_RESP_ERR_REBALANCE_IN_PROGRESS => RebalanceInProgress,
        RD_KAFKA_RESP_ERR_INVALID_COMMIT_OFFSET_SIZE => InvalidCommitOffsetSize,
        RD_KAFKA_RESP_ERR_TOPIC_AUTHORIZATION_FAILED => TopicAuthorizationFailed,
        RD_KAFKA_RESP_ERR_GROUP_AUTHORIZATION_FAILED => GroupAuthorizationFailed,
        RD_KAFKA_RESP_ERR_CLUSTER_AUTHORIZATION_FAILED => ClusterAuthorizationFailed,
        RD_KAFKA_RESP_ERR_INVALID_TIMESTAMP => InvalidTimestamp,
        RD_KAFKA_RESP_ERR_UNSUPPORTED_SASL_MECHANISM => UnsupportedSASLMechanism,
        RD_KAFKA_RESP_ERR_ILLEGAL_SASL_STATE => IllegalSASLState,
        RD_KAFKA_RESP_ERR_UNSUPPORTED_VERSION => UnsupportedVersion,
        RD_KAFKA_RESP_ERR_TOPIC_ALREADY_EXISTS => TopicAlreadyExists,
        RD_KAFKA_RESP_ERR_INVALID_PARTITIONS => InvalidPartitions,
        RD_KAFKA_RESP_ERR_INVALID_REPLICATION_FACTOR => InvalidReplicationFactor,
        RD_KAFKA_RESP_ERR_INVALID_REPLICA_ASSIGNMENT => InvalidReplicaAssignment,
        RD_KAFKA_RESP_ERR_INVALID_CONFIG => InvalidConfig,
        RD_KAFKA_RESP_ERR_NOT_CONTROLLER => NotController,
        RD_KAFKA_RESP_ERR_INVALID_REQUEST => InvalidRequest,
        RD_KAFKA_RESP_ERR_UNSUPPORTED_FOR_MESSAGE_FORMAT => UnsupportedForMessageFormat,
        RD_KAFKA_RESP_ERR_POLICY_VIOLATION => PolicyViolation,
        RD_KAFKA_RESP_ERR_OUT_OF_ORDER_SEQUENCE_NUMBER => OutOfOrderSequenceNumber,
        RD_KAFKA_RESP_ERR_DUPLICATE_SEQUENCE_NUMBER => DuplicateSequenceNumber,
        RD_KAFKA_RESP_ERR_INVALID_PRODUCER_EPOCH => InvalidProducerEpoch,
        RD_KAFKA_RESP_ERR_INVALID_TXN_STATE => InvalidTransactionalState,
        RD_KAFKA_RESP_ERR_INVALID_PRODUCER_ID_MAPPING => InvalidProducerIdMapping,
        RD_KAFKA_RESP_ERR_INVALID_TRANSACTION_TIMEOUT => InvalidTransactionTimeout,
        RD_KAFKA_RESP_ERR_CONCURRENT_TRANSACTIONS => ConcurrentTransactions,
        RD_KAFKA_RESP_ERR_TRANSACTION_COORDINATOR_FENCED => TransactionCoordinatorFenced,
        RD_KAFKA_RESP_ERR_TRANSACTIONAL_ID_AUTHORIZATION_FAILED => TransactionalIdAuthorizationFailed,
        RD_KAFKA_RESP_ERR_SECURITY_DISABLED => SecurityDisabled,
        RD_KAFKA_RESP_ERR_OPERATION_NOT_ATTEMPTED => OperationNotAttempted,
        RD_KAFKA_RESP_ERR_KAFKA_STORAGE_ERROR => KafkaStorageError,
        RD_KAFKA_RESP_ERR_LOG_DIR_NOT_FOUND => LogDirNotFound,
        RD_KAFKA_RESP_ERR_SASL_AUTHENTICATION_FAILED => SaslAuthenticationFailed,
        RD_KAFKA_RESP_ERR_UNKNOWN_PRODUCER_ID => UnknownProducerId,
        RD_KAFKA_RESP_ERR_REASSIGNMENT_IN_PROGRESS => ReassignmentInProgress,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_AUTH_DISABLED => DelegationTokenAuthDisabled,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_NOT_FOUND => DelegationTokenNotFound,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_OWNER_MISMATCH => DelegationTokenOwnerMismatch,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_REQUEST_NOT_ALLOWED => DelegationTokenRequestNotAllowed,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_AUTHORIZATION_FAILED => DelegationTokenAuthorizationFailed,
        RD_KAFKA_RESP_ERR_DELEGATION_TOKEN_EXPIRED => DelegationTokenExpired,
        RD_KAFKA_RESP_ERR_INVALID_PRINCIPAL_TYPE => InvalidPrincipalType,
        RD_KAFKA_RESP_ERR_NON_EMPTY_GROUP => NonEmptyGroup,
        RD_KAFKA_RESP_ERR_GROUP_ID_NOT_FOUND => GroupIdNotFound,
        RD_KAFKA_RESP_ERR_FETCH_SESSION_ID_NOT_FOUND => FetchSessionIdNotFound,
        RD_KAFKA_RESP_ERR_INVALID_FETCH_SESSION_EPOCH => InvalidFetchSessionEpoch,
        RD_KAFKA_RESP_ERR_LISTENER_NOT_FOUND => ListenerNotFound,
        RD_KAFKA_RESP_ERR_TOPIC_DELETION_DISABLED => TopicDeletionDisabled,
        RD_KAFKA_RESP_ERR_UNSUPPORTED_COMPRESSION_TYPE => UnsupportedCompressionType,
        RD_KAFKA_RESP_ERR_END_ALL => EndAll,
    }
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_conversion() {
        for error_code in -299..300 {
            if let Some(resp_err) = primitive_to_rd_kafka_resp_err_t(error_code) {
                let kafka_error = rd_kafka_resp_err_t_to_rdkafka_error(resp_err);
                assert_eq!(error_code, kafka_error as i32);
            }
        }
    }
}