github.com/deanMdreon/kafka-go@v0.4.32/kafka.go (about) 1 package kafka 2 3 import "github.com/deanMdreon/kafka-go/protocol" 4 5 // Broker represents a kafka broker in a kafka cluster. 6 type Broker struct { 7 Host string 8 Port int 9 ID int 10 Rack string 11 } 12 13 // Topic represents a topic in a kafka cluster. 14 type Topic struct { 15 // Name of the topic. 16 Name string 17 18 // True if the topic is internal. 19 Internal bool 20 21 // The list of partition currently available on this topic. 22 Partitions []Partition 23 24 // An error that may have occurred while attempting to read the topic 25 // metadata. 26 // 27 // The error contains both the kafka error code, and an error message 28 // returned by the kafka broker. Programs may use the standard errors.Is 29 // function to test the error against kafka error codes. 30 Error error 31 } 32 33 // Partition carries the metadata associated with a kafka partition. 34 type Partition struct { 35 // Name of the topic that the partition belongs to, and its index in the 36 // topic. 37 Topic string 38 ID int 39 40 // Leader, replicas, and ISR for the partition. 41 Leader Broker 42 Replicas []Broker 43 Isr []Broker 44 45 // An error that may have occurred while attempting to read the partition 46 // metadata. 47 // 48 // The error contains both the kafka error code, and an error message 49 // returned by the kafka broker. Programs may use the standard errors.Is 50 // function to test the error against kafka error codes. 51 Error error 52 } 53 54 // Marshal encodes v into a binary representation of the value in the kafka data 55 // format. 56 // 57 // If v is a, or contains struct types, the kafka struct fields are interpreted 58 // and may contain one of these values: 59 // 60 // nullable valid on bytes and strings, encodes as a nullable value 61 // compact valid on strings, encodes as a compact string 62 // 63 // The kafka struct tags should not contain min and max versions. If you need to 64 // encode types based on specific versions of kafka APIs, use the Version type 65 // instead. 66 func Marshal(v interface{}) ([]byte, error) { 67 return protocol.Marshal(-1, v) 68 } 69 70 // Unmarshal decodes a binary representation from b into v. 71 // 72 // See Marshal for details. 73 func Unmarshal(b []byte, v interface{}) error { 74 return protocol.Unmarshal(b, -1, v) 75 } 76 77 // Version represents a version number for kafka APIs. 78 type Version int16 79 80 // Marshal is like the top-level Marshal function, but will only encode struct 81 // fields for which n falls within the min and max versions specified on the 82 // struct tag. 83 func (n Version) Marshal(v interface{}) ([]byte, error) { 84 return protocol.Marshal(int16(n), v) 85 } 86 87 // Unmarshal is like the top-level Unmarshal function, but will only decode 88 // struct fields for which n falls within the min and max versions specified on 89 // the struct tag. 90 func (n Version) Unmarshal(b []byte, v interface{}) error { 91 return protocol.Unmarshal(b, int16(n), v) 92 }