response_header.go 569 B

123456789101112131415161718192021222324252627
  1. package sarama
  2. import "fmt"
  3. type responseHeader struct {
  4. length int32
  5. correlationID int32
  6. }
  7. func (r *responseHeader) decode(pd packetDecoder) (err error) {
  8. r.length, err = pd.getInt32()
  9. if err != nil {
  10. return err
  11. }
  12. if r.length <= 4 || r.length > MaxResponseSize {
  13. return PacketDecodingError{fmt.Sprintf("message of length %d too large or too small", r.length)}
  14. }
  15. r.correlationID, err = pd.getInt32()
  16. return err
  17. }
  18. func (r *responseHeader) encode(pe packetEncoder) (err error) {
  19. pe.putInt32(r.length)
  20. pe.putInt32(r.correlationID)
  21. return nil
  22. }