createpartitions.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package createpartitions
  2. import "github.com/segmentio/kafka-go/protocol"
  3. func init() {
  4. protocol.Register(&Request{}, &Response{})
  5. }
  6. // Detailed API definition: https://kafka.apache.org/protocol#The_Messages_CreatePartitions.
  7. // TODO: Support version 2
  8. type Request struct {
  9. Topics []RequestTopic `kafka:"min=v0,max=v1"`
  10. TimeoutMs int32 `kafka:"min=v0,max=v1"`
  11. ValidateOnly bool `kafka:"min=v0,max=v1"`
  12. }
  13. func (r *Request) ApiKey() protocol.ApiKey { return protocol.CreatePartitions }
  14. func (r *Request) Broker(cluster protocol.Cluster) (protocol.Broker, error) {
  15. return cluster.Brokers[cluster.Controller], nil
  16. }
  17. type RequestTopic struct {
  18. Name string `kafka:"min=v0,max=v1"`
  19. Count int32 `kafka:"min=v0,max=v1"`
  20. Assignments []RequestAssignment `kafka:"min=v0,max=v1"`
  21. }
  22. type RequestAssignment struct {
  23. BrokerIDs []int32 `kafka:"min=v0,max=v1"`
  24. }
  25. type Response struct {
  26. ThrottleTimeMs int32 `kafka:"min=v0,max=v1"`
  27. Results []ResponseResult `kafka:"min=v0,max=v1"`
  28. }
  29. func (r *Response) ApiKey() protocol.ApiKey { return protocol.CreatePartitions }
  30. type ResponseResult struct {
  31. Name string `kafka:"min=v0,max=v1"`
  32. ErrorCode int16 `kafka:"min=v0,max=v1"`
  33. ErrorMessage string `kafka:"min=v0,max=v1,nullable"`
  34. }
  35. var (
  36. _ protocol.BrokerMessage = (*Request)(nil)
  37. )