From 07eec6803740ca0a64e7b1177fcfe40e6e0e1751 Mon Sep 17 00:00:00 2001 From: Willem van Bergen Date: Mon, 7 Dec 2015 11:21:31 -0500 Subject: [PATCH] Add Heartbeat request and response pair. --- heartbeat_request.go | 48 +++++++++++++++++++++++++++++++++++++++++++ heartbeat_response.go | 15 ++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 heartbeat_request.go create mode 100644 heartbeat_response.go diff --git a/heartbeat_request.go b/heartbeat_request.go new file mode 100644 index 000000000..b67e9a992 --- /dev/null +++ b/heartbeat_request.go @@ -0,0 +1,48 @@ +package sarama + +// HeartbeatRequest => GroupId GenerationId MemberId +// GroupId => string +// GenerationId => int32 +// MemberId => string + +type HeartbeatRequest struct { + GroupId string + GenerationId string + MemberId string +} + +func (r *HeartbeatRequest) encode(pe packetEncoder) error { + if err := pe.putString(r.GroupId); err != nil { + return err + } + if err := pe.putString(r.GenerationId); err != nil { + return err + } + if err := pe.putString(r.MemberId); err != nil { + return err + } + + return nil +} + +func (r *HeartbeatRequest) decode(pd packetDecoder) (err error) { + if r.GroupId, err = pd.getString(); err != nil { + return + } + if r.GenerationId, err = pd.getString(); err != nil { + return + } + if r.MemberId, err = pd.getString(); err != nil { + return + } + + return nil +} + +func (r *HeartbeatRequest) key() int16 { + return 12 +} + +func (r *HeartbeatRequest) version() int16 { + return 0 +} diff --git a/heartbeat_response.go b/heartbeat_response.go new file mode 100644 index 000000000..6c5e263a8 --- /dev/null +++ b/heartbeat_response.go @@ -0,0 +1,15 @@ +package sarama + +type HeartbeatResponse struct { + ErrorCode int16 +} + +func (r *HeartbeatResponse) encode(pe packetEncoder) error { + pe.putInt16(r.ErrorCode) + return nil +} + +func (r *HeartbeatResponse) decode(pd packetDecoder) (err error) { + r.ErrorCode, err = pd.getInt16() + return +}