MCPcopy Create free account
hub / github.com/IBM/sarama / encode

Method encode

offset_fetch_request.go:79–172  ·  view source on GitHub ↗
(pe packetEncoder)

Source from the content-addressed store, hash-verified

77}
78
79func (r *OffsetFetchRequest) encode(pe packetEncoder) (err error) {
80 if r.Version < 0 || r.Version > 8 {
81 return PacketEncodingError{"invalid or unsupported OffsetFetchRequest version field"}
82 }
83
84 if r.RequireStable && r.Version < 7 {
85 return PacketEncodingError{"requireStable is not supported. use version 7 or later"}
86 }
87
88 if r.Version >= 8 {
89 if len(r.Groups) == 0 {
90 return PacketEncodingError{"version 8 or later requires Groups to be populated"}
91 }
92 if err := pe.putArrayLength(len(r.Groups)); err != nil {
93 return err
94 }
95 for _, g := range r.Groups {
96 if err := pe.putString(g.GroupId); err != nil {
97 return err
98 }
99
100 // nil Partitions encodes as null topics array (fetch all)
101 topicCount := len(g.Partitions)
102 if g.Partitions == nil {
103 topicCount = -1
104 }
105 if err := pe.putArrayLength(topicCount); err != nil {
106 return err
107 }
108 for topic, partitions := range g.Partitions {
109 if err := pe.putString(topic); err != nil {
110 return err
111 }
112 if err := pe.putInt32Array(partitions); err != nil {
113 return err
114 }
115 pe.putEmptyTaggedFieldArray()
116 }
117
118 pe.putEmptyTaggedFieldArray()
119 }
120
121 pe.putBool(r.RequireStable)
122 pe.putEmptyTaggedFieldArray()
123 return nil
124 }
125
126 if len(r.Groups) > 1 {
127 return PacketEncodingError{"multiple groups require version 8 or later"}
128 }
129
130 consumerGroup := r.ConsumerGroup
131 partitions := r.partitions
132 if consumerGroup == "" && len(r.Groups) == 1 {
133 consumerGroup = r.Groups[0].GroupId
134 partitions = r.Groups[0].Partitions
135 }
136

Callers

nothing calls this directly

Calls 5

putArrayLengthMethod · 0.65
putStringMethod · 0.65
putInt32ArrayMethod · 0.65
putBoolMethod · 0.65

Tested by

no test coverage detected