add_partitions_to_txn_request.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package sarama
  2. type AddPartitionsToTxnRequest struct {
  3. TransactionalID string
  4. ProducerID int64
  5. ProducerEpoch int16
  6. TopicPartitions map[string][]int32
  7. }
  8. func (a *AddPartitionsToTxnRequest) encode(pe packetEncoder) error {
  9. if err := pe.putString(a.TransactionalID); err != nil {
  10. return err
  11. }
  12. pe.putInt64(a.ProducerID)
  13. pe.putInt16(a.ProducerEpoch)
  14. if err := pe.putArrayLength(len(a.TopicPartitions)); err != nil {
  15. return err
  16. }
  17. for topic, partitions := range a.TopicPartitions {
  18. if err := pe.putString(topic); err != nil {
  19. return err
  20. }
  21. if err := pe.putInt32Array(partitions); err != nil {
  22. return err
  23. }
  24. }
  25. return nil
  26. }
  27. func (a *AddPartitionsToTxnRequest) decode(pd packetDecoder, version int16) (err error) {
  28. if a.TransactionalID, err = pd.getString(); err != nil {
  29. return err
  30. }
  31. if a.ProducerID, err = pd.getInt64(); err != nil {
  32. return err
  33. }
  34. if a.ProducerEpoch, err = pd.getInt16(); err != nil {
  35. return err
  36. }
  37. n, err := pd.getArrayLength()
  38. if err != nil {
  39. return err
  40. }
  41. a.TopicPartitions = make(map[string][]int32)
  42. for i := 0; i < n; i++ {
  43. topic, err := pd.getString()
  44. if err != nil {
  45. return err
  46. }
  47. partitions, err := pd.getInt32Array()
  48. if err != nil {
  49. return err
  50. }
  51. a.TopicPartitions[topic] = partitions
  52. }
  53. return nil
  54. }
  55. func (a *AddPartitionsToTxnRequest) key() int16 {
  56. return 24
  57. }
  58. func (a *AddPartitionsToTxnRequest) version() int16 {
  59. return 0
  60. }
  61. func (a *AddPartitionsToTxnRequest) requiredVersion() KafkaVersion {
  62. return V0_11_0_0
  63. }