|
|
@@ -8,14 +8,14 @@ type FetchResponseBlock struct {
|
|
|
MsgSet MessageSet
|
|
|
}
|
|
|
|
|
|
-func (pr *FetchResponseBlock) decode(pd packetDecoder) (err error) {
|
|
|
+func (b *FetchResponseBlock) decode(pd packetDecoder) (err error) {
|
|
|
tmp, err := pd.getInt16()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- pr.Err = KError(tmp)
|
|
|
+ b.Err = KError(tmp)
|
|
|
|
|
|
- pr.HighWaterMarkOffset, err = pd.getInt64()
|
|
|
+ b.HighWaterMarkOffset, err = pd.getInt64()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -29,39 +29,39 @@ func (pr *FetchResponseBlock) decode(pd packetDecoder) (err error) {
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = (&pr.MsgSet).decode(msgSetDecoder)
|
|
|
+ err = (&b.MsgSet).decode(msgSetDecoder)
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-type FetchResponse struct {
|
|
|
- Blocks map[string]map[int32]*FetchResponseBlock
|
|
|
- ThrottleTime time.Duration
|
|
|
- Version int16 // v1 requires 0.9+, v2 requires 0.10+
|
|
|
-}
|
|
|
-
|
|
|
-func (pr *FetchResponseBlock) encode(pe packetEncoder) (err error) {
|
|
|
- pe.putInt16(int16(pr.Err))
|
|
|
+func (b *FetchResponseBlock) encode(pe packetEncoder) (err error) {
|
|
|
+ pe.putInt16(int16(b.Err))
|
|
|
|
|
|
- pe.putInt64(pr.HighWaterMarkOffset)
|
|
|
+ pe.putInt64(b.HighWaterMarkOffset)
|
|
|
|
|
|
pe.push(&lengthField{})
|
|
|
- err = pr.MsgSet.encode(pe)
|
|
|
+ err = b.MsgSet.encode(pe)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return pe.pop()
|
|
|
}
|
|
|
|
|
|
-func (fr *FetchResponse) decode(pd packetDecoder, version int16) (err error) {
|
|
|
- fr.Version = version
|
|
|
+type FetchResponse struct {
|
|
|
+ Blocks map[string]map[int32]*FetchResponseBlock
|
|
|
+ ThrottleTime time.Duration
|
|
|
+ Version int16 // v1 requires 0.9+, v2 requires 0.10+
|
|
|
+}
|
|
|
+
|
|
|
+func (r *FetchResponse) decode(pd packetDecoder, version int16) (err error) {
|
|
|
+ r.Version = version
|
|
|
|
|
|
- if fr.Version >= 1 {
|
|
|
+ if r.Version >= 1 {
|
|
|
throttle, err := pd.getInt32()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- fr.ThrottleTime = time.Duration(throttle) * time.Millisecond
|
|
|
+ r.ThrottleTime = time.Duration(throttle) * time.Millisecond
|
|
|
}
|
|
|
|
|
|
numTopics, err := pd.getArrayLength()
|
|
|
@@ -69,7 +69,7 @@ func (fr *FetchResponse) decode(pd packetDecoder, version int16) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- fr.Blocks = make(map[string]map[int32]*FetchResponseBlock, numTopics)
|
|
|
+ r.Blocks = make(map[string]map[int32]*FetchResponseBlock, numTopics)
|
|
|
for i := 0; i < numTopics; i++ {
|
|
|
name, err := pd.getString()
|
|
|
if err != nil {
|
|
|
@@ -81,7 +81,7 @@ func (fr *FetchResponse) decode(pd packetDecoder, version int16) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- fr.Blocks[name] = make(map[int32]*FetchResponseBlock, numBlocks)
|
|
|
+ r.Blocks[name] = make(map[int32]*FetchResponseBlock, numBlocks)
|
|
|
|
|
|
for j := 0; j < numBlocks; j++ {
|
|
|
id, err := pd.getInt32()
|
|
|
@@ -94,24 +94,24 @@ func (fr *FetchResponse) decode(pd packetDecoder, version int16) (err error) {
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- fr.Blocks[name][id] = block
|
|
|
+ r.Blocks[name][id] = block
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (fr *FetchResponse) encode(pe packetEncoder) (err error) {
|
|
|
- if fr.Version >= 1 {
|
|
|
- pe.putInt32(int32(fr.ThrottleTime / time.Millisecond))
|
|
|
+func (r *FetchResponse) encode(pe packetEncoder) (err error) {
|
|
|
+ if r.Version >= 1 {
|
|
|
+ pe.putInt32(int32(r.ThrottleTime / time.Millisecond))
|
|
|
}
|
|
|
|
|
|
- err = pe.putArrayLength(len(fr.Blocks))
|
|
|
+ err = pe.putArrayLength(len(r.Blocks))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- for topic, partitions := range fr.Blocks {
|
|
|
+ for topic, partitions := range r.Blocks {
|
|
|
err = pe.putString(topic)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -153,26 +153,26 @@ func (r *FetchResponse) requiredVersion() KafkaVersion {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (fr *FetchResponse) GetBlock(topic string, partition int32) *FetchResponseBlock {
|
|
|
- if fr.Blocks == nil {
|
|
|
+func (r *FetchResponse) GetBlock(topic string, partition int32) *FetchResponseBlock {
|
|
|
+ if r.Blocks == nil {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- if fr.Blocks[topic] == nil {
|
|
|
+ if r.Blocks[topic] == nil {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- return fr.Blocks[topic][partition]
|
|
|
+ return r.Blocks[topic][partition]
|
|
|
}
|
|
|
|
|
|
-func (fr *FetchResponse) AddError(topic string, partition int32, err KError) {
|
|
|
- if fr.Blocks == nil {
|
|
|
- fr.Blocks = make(map[string]map[int32]*FetchResponseBlock)
|
|
|
+func (r *FetchResponse) AddError(topic string, partition int32, err KError) {
|
|
|
+ if r.Blocks == nil {
|
|
|
+ r.Blocks = make(map[string]map[int32]*FetchResponseBlock)
|
|
|
}
|
|
|
- partitions, ok := fr.Blocks[topic]
|
|
|
+ partitions, ok := r.Blocks[topic]
|
|
|
if !ok {
|
|
|
partitions = make(map[int32]*FetchResponseBlock)
|
|
|
- fr.Blocks[topic] = partitions
|
|
|
+ r.Blocks[topic] = partitions
|
|
|
}
|
|
|
frb, ok := partitions[partition]
|
|
|
if !ok {
|
|
|
@@ -182,14 +182,14 @@ func (fr *FetchResponse) AddError(topic string, partition int32, err KError) {
|
|
|
frb.Err = err
|
|
|
}
|
|
|
|
|
|
-func (fr *FetchResponse) AddMessage(topic string, partition int32, key, value Encoder, offset int64) {
|
|
|
- if fr.Blocks == nil {
|
|
|
- fr.Blocks = make(map[string]map[int32]*FetchResponseBlock)
|
|
|
+func (r *FetchResponse) AddMessage(topic string, partition int32, key, value Encoder, offset int64) {
|
|
|
+ if r.Blocks == nil {
|
|
|
+ r.Blocks = make(map[string]map[int32]*FetchResponseBlock)
|
|
|
}
|
|
|
- partitions, ok := fr.Blocks[topic]
|
|
|
+ partitions, ok := r.Blocks[topic]
|
|
|
if !ok {
|
|
|
partitions = make(map[int32]*FetchResponseBlock)
|
|
|
- fr.Blocks[topic] = partitions
|
|
|
+ r.Blocks[topic] = partitions
|
|
|
}
|
|
|
frb, ok := partitions[partition]
|
|
|
if !ok {
|