diff --git a/proto/marshal.go b/proto/marshal.go index d01514e..1d96805 100644 --- a/proto/marshal.go +++ b/proto/marshal.go @@ -1,2396 +1,726 @@ package proto -import ( - "io" -) +func (t *RequestOrResponse) Marshal(w *Writer) { + w.WriteInt32(t.Size) + t.T.Marshal(w) +} -func (t *RequestOrResponse) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Size >> 24), byte(t.Size >> 16), byte(t.Size >> 8), byte(t.Size)}); err != nil { - return err - } - if err := t.T.Marshal(w); err != nil { - return err - } - return nil +func (t *RequestOrResponse) Unmarshal(r *Reader) { + t.Size = r.ReadInt32() + t.T.Unmarshal(r) } -func (t *RequestOrResponse) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Size = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - if err := t.T.Unmarshal(r); err != nil { - return err - } - } - return nil +func (t *Request) Marshal(w *Writer) { + w.WriteInt16(t.APIKey) + w.WriteInt16(t.APIVersion) + w.WriteInt32(t.CorrelationID) + w.WriteString(string(t.ClientID)) + t.RequestMessage.Marshal(w) } -func (t *Request) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.APIKey >> 8), byte(t.APIKey)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.APIVersion >> 8), byte(t.APIVersion)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.CorrelationID >> 24), byte(t.CorrelationID >> 16), byte(t.CorrelationID >> 8), byte(t.CorrelationID)}); err != nil { - return err - } - { - l := int16(len(t.ClientID)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ClientID)); err != nil { - return err - } - } - if err := t.RequestMessage.Marshal(w); err != nil { - return err - } - return nil +func (t *Request) Unmarshal(r *Reader) { + t.APIKey = r.ReadInt16() + t.APIVersion = r.ReadInt16() + t.CorrelationID = r.ReadInt32() + t.ClientID = string(r.ReadString()) + t.RequestMessage.Unmarshal(r) } -func (t *Request) Unmarshal(r io.Reader) error { - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.APIKey = int16(b[0])<<8 | int16(b[1]) - } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.APIVersion = int16(b[0])<<8 | int16(b[1]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.CorrelationID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ClientID = string(b) - } - { - if err := t.RequestMessage.Unmarshal(r); err != nil { - return err - } - } - return nil +func (t *Response) Marshal(w *Writer) { + w.WriteInt32(t.CorrelationID) + t.ResponseMessage.Marshal(w) } -func (t *Response) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.CorrelationID >> 24), byte(t.CorrelationID >> 16), byte(t.CorrelationID >> 8), byte(t.CorrelationID)}); err != nil { - return err - } - if err := t.ResponseMessage.Marshal(w); err != nil { - return err - } - return nil +func (t *Response) Unmarshal(r *Reader) { + t.CorrelationID = r.ReadInt32() + t.ResponseMessage.Unmarshal(r) } -func (t *Response) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.CorrelationID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - if err := t.ResponseMessage.Unmarshal(r); err != nil { - return err - } - } - return nil -} - -func (t *MessageSet) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } +func (t *MessageSet) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - return nil -} - -func (t *MessageSet) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]SizedMessage, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil } -func (t *SizedMessage) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MessageSize >> 24), byte(t.MessageSize >> 16), byte(t.MessageSize >> 8), byte(t.MessageSize)}); err != nil { - return err - } - if err := t.Message.Marshal(w); err != nil { - return err +func (t *MessageSet) Unmarshal(r *Reader) { + (*t) = make([]SizedMessage, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - return nil } -func (t *SizedMessage) Unmarshal(r io.Reader) error { - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MessageSize = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - if err := t.Message.Unmarshal(r); err != nil { - return err - } - } - return nil +func (t *SizedMessage) Marshal(w *Writer) { + w.WriteInt64(t.Offset) + w.WriteInt32(t.MessageSize) + t.Message.Marshal(w) } -func (t *Message) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.CRC >> 24), byte(t.CRC >> 16), byte(t.CRC >> 8), byte(t.CRC)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MagicByte)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Attributes)}); err != nil { - return err - } - { - l := int32(len(t.Key)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write(t.Key); err != nil { - return err - } - } - { - l := int32(len(t.Value)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write(t.Value); err != nil { - return err - } - } - return nil +func (t *SizedMessage) Unmarshal(r *Reader) { + t.Offset = r.ReadInt64() + t.MessageSize = r.ReadInt32() + t.Message.Unmarshal(r) } -func (t *Message) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.CRC = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [1]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MagicByte = int8(b[0]) - } - { - var b [1]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Attributes = int8(b[0]) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Key = b - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Value = b - } - return nil -} - -func (t *TopicMetadataRequest) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - { - l := int16(len((*t)[i])) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte((*t)[i])); err != nil { - return err - } - } - } - } - return nil -} - -func (t *TopicMetadataRequest) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]string, int(l)) - for i := range *t { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - (*t)[i] = string(b) - } - } - } - return nil -} - -func (t *MetadataResponse) Marshal(w io.Writer) error { - { - l := int32(len(t.Brokers)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.Brokers { - if err := t.Brokers[i].Marshal(w); err != nil { - return err - } - } - } - { - l := int32(len(t.TopicMetadatas)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.TopicMetadatas { - if err := t.TopicMetadatas[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *MetadataResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.Brokers = make([]Broker, int(l)) - for i := range t.Brokers { - if err := t.Brokers[i].Unmarshal(r); err != nil { - return err - } - } - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.TopicMetadatas = make([]TopicMetadata, int(l)) - for i := range t.TopicMetadatas { - if err := t.TopicMetadatas[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil +func (t *Message) Marshal(w *Writer) { + w.WriteInt32(t.CRC) + w.WriteInt8(t.MagicByte) + w.WriteInt8(t.Attributes) + w.WriteBytes(t.Key) + w.WriteBytes(t.Value) } -func (t *Broker) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.NodeID >> 24), byte(t.NodeID >> 16), byte(t.NodeID >> 8), byte(t.NodeID)}); err != nil { - return err - } - { - l := int16(len(t.Host)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.Host)); err != nil { - return err - } - } - if _, err := w.Write([]byte{byte(t.Port >> 24), byte(t.Port >> 16), byte(t.Port >> 8), byte(t.Port)}); err != nil { - return err - } - return nil +func (t *Message) Unmarshal(r *Reader) { + t.CRC = r.ReadInt32() + t.MagicByte = r.ReadInt8() + t.Attributes = r.ReadInt8() + t.Key = r.ReadBytes() + t.Value = r.ReadBytes() } -func (t *Broker) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.NodeID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Host = string(b) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Port = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +func (t *TopicMetadataRequest) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + w.WriteString(string((*t)[i])) } - return nil } -func (t *TopicMetadata) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.TopicErrorCode >> 8), byte(t.TopicErrorCode)}); err != nil { - return err +func (t *TopicMetadataRequest) Unmarshal(r *Reader) { + (*t) = make([]string, int(r.ReadInt32())) + for i := range *t { + (*t)[i] = string(r.ReadString()) } - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.PartitionMetadatas)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.PartitionMetadatas { - if err := t.PartitionMetadatas[i].Marshal(w); err != nil { - return err - } - } - } - return nil } -func (t *TopicMetadata) Unmarshal(r io.Reader) error { - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.TopicErrorCode = int16(b[0])<<8 | int16(b[1]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) +func (t *MetadataResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len(t.Brokers))) + for i := range t.Brokers { + t.Brokers[i].Marshal(w) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.PartitionMetadatas = make([]PartitionMetadata, int(l)) - for i := range t.PartitionMetadatas { - if err := t.PartitionMetadatas[i].Unmarshal(r); err != nil { - return err - } - } + w.WriteInt32(int32(len(t.TopicMetadatas))) + for i := range t.TopicMetadatas { + t.TopicMetadatas[i].Marshal(w) } - return nil } -func (t *PartitionMetadata) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.PartitionErrorCode >> 8), byte(t.PartitionErrorCode)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.PartitionID >> 24), byte(t.PartitionID >> 16), byte(t.PartitionID >> 8), byte(t.PartitionID)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Leader >> 24), byte(t.Leader >> 16), byte(t.Leader >> 8), byte(t.Leader)}); err != nil { - return err +func (t *MetadataResponse) Unmarshal(r *Reader) { + t.Brokers = make([]Broker, int(r.ReadInt32())) + for i := range t.Brokers { + t.Brokers[i].Unmarshal(r) } - if _, err := w.Write([]byte{byte(t.Replicas >> 24), byte(t.Replicas >> 16), byte(t.Replicas >> 8), byte(t.Replicas)}); err != nil { - return err + t.TopicMetadatas = make([]TopicMetadata, int(r.ReadInt32())) + for i := range t.TopicMetadatas { + t.TopicMetadatas[i].Unmarshal(r) } - if _, err := w.Write([]byte{byte(t.ISR >> 24), byte(t.ISR >> 16), byte(t.ISR >> 8), byte(t.ISR)}); err != nil { - return err - } - return nil } -func (t *PartitionMetadata) Unmarshal(r io.Reader) error { - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.PartitionErrorCode = int16(b[0])<<8 | int16(b[1]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.PartitionID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Leader = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Replicas = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ISR = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - return nil +func (t *Broker) Marshal(w *Writer) { + w.WriteInt32(t.NodeID) + w.WriteString(string(t.Host)) + w.WriteInt32(t.Port) } -func (t *ProduceRequest) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.RequiredAcks >> 8), byte(t.RequiredAcks)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Timeout >> 24), byte(t.Timeout >> 16), byte(t.Timeout >> 8), byte(t.Timeout)}); err != nil { - return err - } - { - l := int32(len(t.MessageSetInTopics)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.MessageSetInTopics { - if err := t.MessageSetInTopics[i].Marshal(w); err != nil { - return err - } - } - } - return nil +func (t *Broker) Unmarshal(r *Reader) { + t.NodeID = r.ReadInt32() + t.Host = string(r.ReadString()) + t.Port = r.ReadInt32() } -func (t *ProduceRequest) Unmarshal(r io.Reader) error { - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.RequiredAcks = int16(b[0])<<8 | int16(b[1]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Timeout = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.MessageSetInTopics = make([]MessageSetInTopic, int(l)) - for i := range t.MessageSetInTopics { - if err := t.MessageSetInTopics[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *MessageSetInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.MessageSetInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.MessageSetInPartitions { - if err := t.MessageSetInPartitions[i].Marshal(w); err != nil { - return err - } - } +func (t *TopicMetadata) Marshal(w *Writer) { + w.WriteInt16(t.TopicErrorCode) + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.PartitionMetadatas))) + for i := range t.PartitionMetadatas { + t.PartitionMetadatas[i].Marshal(w) } - return nil -} - -func (t *MessageSetInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.MessageSetInPartitions = make([]MessageSetInPartition, int(l)) - for i := range t.MessageSetInPartitions { - if err := t.MessageSetInPartitions[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil } -func (t *MessageSetInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MessageSetSize >> 24), byte(t.MessageSetSize >> 16), byte(t.MessageSetSize >> 8), byte(t.MessageSetSize)}); err != nil { - return err +func (t *TopicMetadata) Unmarshal(r *Reader) { + t.TopicErrorCode = r.ReadInt16() + t.TopicName = string(r.ReadString()) + t.PartitionMetadatas = make([]PartitionMetadata, int(r.ReadInt32())) + for i := range t.PartitionMetadatas { + t.PartitionMetadatas[i].Unmarshal(r) } - if err := t.MessageSet.Marshal(w); err != nil { - return err - } - return nil } -func (t *MessageSetInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MessageSetSize = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - if err := t.MessageSet.Unmarshal(r); err != nil { - return err - } - } - return nil -} - -func (t *ProduceResponse) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *ProduceResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]OffsetInTopic, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - if err := t.OffsetInPartitions.Marshal(w); err != nil { - return err - } - return nil -} - -func (t *OffsetInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - if err := t.OffsetInPartitions.Unmarshal(r); err != nil { - return err - } - } - return nil -} - -func (t *OffsetInPartitions) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetInPartitions) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]OffsetInPartition, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil +func (t *PartitionMetadata) Marshal(w *Writer) { + w.WriteInt16(t.PartitionErrorCode) + w.WriteInt32(t.PartitionID) + w.WriteInt32(t.Leader) + w.WriteInt32(t.Replicas) + w.WriteInt32(t.ISR) } -func (t *OffsetInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err - } - return nil +func (t *PartitionMetadata) Unmarshal(r *Reader) { + t.PartitionErrorCode = r.ReadInt16() + t.PartitionID = r.ReadInt32() + t.Leader = r.ReadInt32() + t.Replicas = r.ReadInt32() + t.ISR = r.ReadInt32() } -func (t *OffsetInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) +func (t *ProduceRequest) Marshal(w *Writer) { + w.WriteInt16(t.RequiredAcks) + w.WriteInt32(t.Timeout) + w.WriteInt32(int32(len(t.MessageSetInTopics))) + for i := range t.MessageSetInTopics { + t.MessageSetInTopics[i].Marshal(w) } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - return nil } -func (t *FetchRequest) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.ReplicaID >> 24), byte(t.ReplicaID >> 16), byte(t.ReplicaID >> 8), byte(t.ReplicaID)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MaxWaitTime >> 24), byte(t.MaxWaitTime >> 16), byte(t.MaxWaitTime >> 8), byte(t.MaxWaitTime)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MinBytes >> 24), byte(t.MinBytes >> 16), byte(t.MinBytes >> 8), byte(t.MinBytes)}); err != nil { - return err +func (t *ProduceRequest) Unmarshal(r *Reader) { + t.RequiredAcks = r.ReadInt16() + t.Timeout = r.ReadInt32() + t.MessageSetInTopics = make([]MessageSetInTopic, int(r.ReadInt32())) + for i := range t.MessageSetInTopics { + t.MessageSetInTopics[i].Unmarshal(r) } - { - l := int32(len(t.FetchOffsetInTopics)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.FetchOffsetInTopics { - if err := t.FetchOffsetInTopics[i].Marshal(w); err != nil { - return err - } - } - } - return nil } -func (t *FetchRequest) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ReplicaID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MaxWaitTime = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MinBytes = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.FetchOffsetInTopics = make([]FetchOffsetInTopic, int(l)) - for i := range t.FetchOffsetInTopics { - if err := t.FetchOffsetInTopics[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *FetchOffsetInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.FetchOffsetInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.FetchOffsetInPartitions { - if err := t.FetchOffsetInPartitions[i].Marshal(w); err != nil { - return err - } - } +func (t *MessageSetInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.MessageSetInPartitions))) + for i := range t.MessageSetInPartitions { + t.MessageSetInPartitions[i].Marshal(w) } - return nil -} - -func (t *FetchOffsetInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.FetchOffsetInPartitions = make([]FetchOffsetInPartition, int(l)) - for i := range t.FetchOffsetInPartitions { - if err := t.FetchOffsetInPartitions[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil } -func (t *FetchOffsetInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.FetchOffset >> 56), byte(t.FetchOffset >> 48), byte(t.FetchOffset >> 40), byte(t.FetchOffset) >> 32, byte(t.FetchOffset >> 24), byte(t.FetchOffset >> 16), byte(t.FetchOffset >> 8), byte(t.FetchOffset)}); err != nil { - return err +func (t *MessageSetInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.MessageSetInPartitions = make([]MessageSetInPartition, int(r.ReadInt32())) + for i := range t.MessageSetInPartitions { + t.MessageSetInPartitions[i].Unmarshal(r) } - if _, err := w.Write([]byte{byte(t.MaxBytes >> 24), byte(t.MaxBytes >> 16), byte(t.MaxBytes >> 8), byte(t.MaxBytes)}); err != nil { - return err - } - return nil } -func (t *FetchOffsetInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.FetchOffset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MaxBytes = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - return nil -} - -func (t *FetchResponse) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *FetchResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]FetchMessageSetInTopic, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *FetchMessageSetInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.FetchMessageSetInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.FetchMessageSetInPartitions { - if err := t.FetchMessageSetInPartitions[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *FetchMessageSetInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.FetchMessageSetInPartitions = make([]FetchMessageSetInPartition, int(l)) - for i := range t.FetchMessageSetInPartitions { - if err := t.FetchMessageSetInPartitions[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil +func (t *MessageSetInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt32(t.MessageSetSize) + t.MessageSet.Marshal(w) } -func (t *FetchMessageSetInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.HighwaterMarkOffset >> 56), byte(t.HighwaterMarkOffset >> 48), byte(t.HighwaterMarkOffset >> 40), byte(t.HighwaterMarkOffset) >> 32, byte(t.HighwaterMarkOffset >> 24), byte(t.HighwaterMarkOffset >> 16), byte(t.HighwaterMarkOffset >> 8), byte(t.HighwaterMarkOffset)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.MessageSetSize >> 24), byte(t.MessageSetSize >> 16), byte(t.MessageSetSize >> 8), byte(t.MessageSetSize)}); err != nil { - return err - } - if err := t.MessageSet.Marshal(w); err != nil { - return err - } - return nil +func (t *MessageSetInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.MessageSetSize = r.ReadInt32() + t.MessageSet.Unmarshal(r) } -func (t *FetchMessageSetInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +func (t *ProduceResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.HighwaterMarkOffset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MessageSetSize = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - if err := t.MessageSet.Unmarshal(r); err != nil { - return err - } - } - return nil } -func (t *OffsetRequest) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.ReplicaID >> 24), byte(t.ReplicaID >> 16), byte(t.ReplicaID >> 8), byte(t.ReplicaID)}); err != nil { - return err - } - { - l := int32(len(t.TimeInTopics)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.TimeInTopics { - if err := t.TimeInTopics[i].Marshal(w); err != nil { - return err - } - } +func (t *ProduceResponse) Unmarshal(r *Reader) { + (*t) = make([]OffsetInTopic, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - return nil } -func (t *OffsetRequest) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ReplicaID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.TimeInTopics = make([]TimeInTopic, int(l)) - for i := range t.TimeInTopics { - if err := t.TimeInTopics[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *TimeInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.TimeInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.TimeInPartitions { - if err := t.TimeInPartitions[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *TimeInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.TimeInPartitions = make([]TimeInPartition, int(l)) - for i := range t.TimeInPartitions { - if err := t.TimeInPartitions[i].Unmarshal(r); err != nil { - return err - } - } +func (t *OffsetInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + t.OffsetInPartitions.Marshal(w) +} + +func (t *OffsetInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetInPartitions.Unmarshal(r) +} + +func (t *OffsetInPartitions) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - return nil } -func (t *TimeInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err +func (t *OffsetInPartitions) Unmarshal(r *Reader) { + (*t) = make([]OffsetInPartition, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - if _, err := w.Write([]byte{byte(t.Time >> 56), byte(t.Time >> 48), byte(t.Time >> 40), byte(t.Time) >> 32, byte(t.Time >> 24), byte(t.Time >> 16), byte(t.Time >> 8), byte(t.Time)}); err != nil { - return err +} + +func (t *OffsetInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt16(t.ErrorCode) + w.WriteInt64(t.Offset) +} + +func (t *OffsetInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.ErrorCode = r.ReadInt16() + t.Offset = r.ReadInt64() +} + +func (t *FetchRequest) Marshal(w *Writer) { + w.WriteInt32(t.ReplicaID) + w.WriteInt32(t.MaxWaitTime) + w.WriteInt32(t.MinBytes) + w.WriteInt32(int32(len(t.FetchOffsetInTopics))) + for i := range t.FetchOffsetInTopics { + t.FetchOffsetInTopics[i].Marshal(w) } - if _, err := w.Write([]byte{byte(t.MaxNumberOfOffsets >> 24), byte(t.MaxNumberOfOffsets >> 16), byte(t.MaxNumberOfOffsets >> 8), byte(t.MaxNumberOfOffsets)}); err != nil { - return err +} + +func (t *FetchRequest) Unmarshal(r *Reader) { + t.ReplicaID = r.ReadInt32() + t.MaxWaitTime = r.ReadInt32() + t.MinBytes = r.ReadInt32() + t.FetchOffsetInTopics = make([]FetchOffsetInTopic, int(r.ReadInt32())) + for i := range t.FetchOffsetInTopics { + t.FetchOffsetInTopics[i].Unmarshal(r) } - return nil } -func (t *TimeInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +func (t *FetchOffsetInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.FetchOffsetInPartitions))) + for i := range t.FetchOffsetInPartitions { + t.FetchOffsetInPartitions[i].Marshal(w) } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Time = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) +} + +func (t *FetchOffsetInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.FetchOffsetInPartitions = make([]FetchOffsetInPartition, int(r.ReadInt32())) + for i := range t.FetchOffsetInPartitions { + t.FetchOffsetInPartitions[i].Unmarshal(r) } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.MaxNumberOfOffsets = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +} + +func (t *FetchOffsetInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.FetchOffset) + w.WriteInt32(t.MaxBytes) +} + +func (t *FetchOffsetInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.FetchOffset = r.ReadInt64() + t.MaxBytes = r.ReadInt32() +} + +func (t *FetchResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - return nil -} - -func (t *OffsetResponse) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } +} + +func (t *FetchResponse) Unmarshal(r *Reader) { + (*t) = make([]FetchMessageSetInTopic, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - return nil -} - -func (t *OffsetResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]OffsetsInTopic, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } +} + +func (t *FetchMessageSetInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.FetchMessageSetInPartitions))) + for i := range t.FetchMessageSetInPartitions { + t.FetchMessageSetInPartitions[i].Marshal(w) } - return nil -} - -func (t *OffsetsInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } +} + +func (t *FetchMessageSetInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.FetchMessageSetInPartitions = make([]FetchMessageSetInPartition, int(r.ReadInt32())) + for i := range t.FetchMessageSetInPartitions { + t.FetchMessageSetInPartitions[i].Unmarshal(r) } - { - l := int32(len(t.OffsetsInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetsInPartitions { - if err := t.OffsetsInPartitions[i].Marshal(w); err != nil { - return err - } - } +} + +func (t *FetchMessageSetInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt16(t.ErrorCode) + w.WriteInt64(t.HighwaterMarkOffset) + w.WriteInt32(t.MessageSetSize) + t.MessageSet.Marshal(w) +} + +func (t *FetchMessageSetInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.ErrorCode = r.ReadInt16() + t.HighwaterMarkOffset = r.ReadInt64() + t.MessageSetSize = r.ReadInt32() + t.MessageSet.Unmarshal(r) +} + +func (t *OffsetRequest) Marshal(w *Writer) { + w.WriteInt32(t.ReplicaID) + w.WriteInt32(int32(len(t.TimeInTopics))) + for i := range t.TimeInTopics { + t.TimeInTopics[i].Marshal(w) } - return nil -} - -func (t *OffsetsInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) +} + +func (t *OffsetRequest) Unmarshal(r *Reader) { + t.ReplicaID = r.ReadInt32() + t.TimeInTopics = make([]TimeInTopic, int(r.ReadInt32())) + for i := range t.TimeInTopics { + t.TimeInTopics[i].Unmarshal(r) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetsInPartitions = make([]OffsetsInPartition, int(l)) - for i := range t.OffsetsInPartitions { - if err := t.OffsetsInPartitions[i].Unmarshal(r); err != nil { - return err - } - } +} + +func (t *TimeInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.TimeInPartitions))) + for i := range t.TimeInPartitions { + t.TimeInPartitions[i].Marshal(w) } - return nil } -func (t *OffsetsInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err +func (t *TimeInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.TimeInPartitions = make([]TimeInPartition, int(r.ReadInt32())) + for i := range t.TimeInPartitions { + t.TimeInPartitions[i].Unmarshal(r) } - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err +} + +func (t *TimeInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.Time) + w.WriteInt32(t.MaxNumberOfOffsets) +} + +func (t *TimeInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.Time = r.ReadInt64() + t.MaxNumberOfOffsets = r.ReadInt32() +} + +func (t *OffsetResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - { - l := int32(len(t.Offsets)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.Offsets { - if _, err := w.Write([]byte{byte(t.Offsets[i] >> 56), byte(t.Offsets[i] >> 48), byte(t.Offsets[i] >> 40), byte(t.Offsets[i]) >> 32, byte(t.Offsets[i] >> 24), byte(t.Offsets[i] >> 16), byte(t.Offsets[i] >> 8), byte(t.Offsets[i])}); err != nil { - return err - } - } +} + +func (t *OffsetResponse) Unmarshal(r *Reader) { + (*t) = make([]OffsetsInTopic, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - return nil } -func (t *OffsetsInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +func (t *OffsetsInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.OffsetsInPartitions))) + for i := range t.OffsetsInPartitions { + t.OffsetsInPartitions[i].Marshal(w) } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) +} + +func (t *OffsetsInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetsInPartitions = make([]OffsetsInPartition, int(r.ReadInt32())) + for i := range t.OffsetsInPartitions { + t.OffsetsInPartitions[i].Unmarshal(r) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.Offsets = make([]int64, int(l)) - for i := range t.Offsets { - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offsets[i] = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - } +} + +func (t *OffsetsInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt16(t.ErrorCode) + w.WriteInt32(int32(len(t.Offsets))) + for i := range t.Offsets { + w.WriteInt64(t.Offsets[i]) } - return nil -} - -func (t *ConsumerMetadataRequest) Marshal(w io.Writer) error { - { - l := int16(len((*t))) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte((*t))); err != nil { - return err - } +} + +func (t *OffsetsInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.ErrorCode = r.ReadInt16() + t.Offsets = make([]int64, int(r.ReadInt32())) + for i := range t.Offsets { + t.Offsets[i] = r.ReadInt64() } - return nil } -func (t *ConsumerMetadataRequest) Unmarshal(r io.Reader) error { +func (t *ConsumerMetadataRequest) Marshal(w *Writer) { + w.WriteString(string((*t))) +} + +func (t *ConsumerMetadataRequest) Unmarshal(r *Reader) { // type ConsumerMetadataRequest, { string []} - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - (*t) = ConsumerMetadataRequest(b) - } - return nil + (*t) = ConsumerMetadataRequest(r.ReadString()) } -func (t *ConsumerMetadataResponse) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.CoordinatorID >> 24), byte(t.CoordinatorID >> 16), byte(t.CoordinatorID >> 8), byte(t.CoordinatorID)}); err != nil { - return err - } - { - l := int16(len(t.CoordinatorHost)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.CoordinatorHost)); err != nil { - return err - } - } - if _, err := w.Write([]byte{byte(t.CoordinatorPort >> 24), byte(t.CoordinatorPort >> 16), byte(t.CoordinatorPort >> 8), byte(t.CoordinatorPort)}); err != nil { - return err - } - return nil +func (t *ConsumerMetadataResponse) Marshal(w *Writer) { + w.WriteInt16(t.ErrorCode) + w.WriteInt32(t.CoordinatorID) + w.WriteString(string(t.CoordinatorHost)) + w.WriteInt32(t.CoordinatorPort) } -func (t *ConsumerMetadataResponse) Unmarshal(r io.Reader) error { - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.CoordinatorID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.CoordinatorHost = string(b) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.CoordinatorPort = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - return nil -} - -func (t *OffsetCommitRequestV0) Marshal(w io.Writer) error { - { - l := int16(len(t.ConsumerGroupID)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerGroupID)); err != nil { - return err - } - } - { - l := int32(len(t.OffsetCommitInTopicV0s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInTopicV0s { - if err := t.OffsetCommitInTopicV0s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitRequestV0) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerGroupID = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInTopicV0s = make([]OffsetCommitInTopicV0, int(l)) - for i := range t.OffsetCommitInTopicV0s { - if err := t.OffsetCommitInTopicV0s[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitInTopicV0) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.OffsetCommitInPartitionV0s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInPartitionV0s { - if err := t.OffsetCommitInPartitionV0s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitInTopicV0) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInPartitionV0s = make([]OffsetCommitInPartitionV0, int(l)) - for i := range t.OffsetCommitInPartitionV0s { - if err := t.OffsetCommitInPartitionV0s[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil +func (t *ConsumerMetadataResponse) Unmarshal(r *Reader) { + t.ErrorCode = r.ReadInt16() + t.CoordinatorID = r.ReadInt32() + t.CoordinatorHost = string(r.ReadString()) + t.CoordinatorPort = r.ReadInt32() } -func (t *OffsetCommitInPartitionV0) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err +func (t *OffsetCommitRequestV0) Marshal(w *Writer) { + w.WriteString(string(t.ConsumerGroupID)) + w.WriteInt32(int32(len(t.OffsetCommitInTopicV0s))) + for i := range t.OffsetCommitInTopicV0s { + t.OffsetCommitInTopicV0s[i].Marshal(w) } - { - l := int16(len(t.Metadata)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.Metadata)); err != nil { - return err - } - } - return nil } -func (t *OffsetCommitInPartitionV0) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Metadata = string(b) - } - return nil -} - -func (t *OffsetCommitRequestV1) Marshal(w io.Writer) error { - { - l := int16(len(t.ConsumerGroupID)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerGroupID)); err != nil { - return err - } - } - if _, err := w.Write([]byte{byte(t.ConsumerGroupGenerationID >> 24), byte(t.ConsumerGroupGenerationID >> 16), byte(t.ConsumerGroupGenerationID >> 8), byte(t.ConsumerGroupGenerationID)}); err != nil { - return err - } - { - l := int16(len(t.ConsumerID)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerID)); err != nil { - return err - } - } - { - l := int32(len(t.OffsetCommitInTopicV1s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInTopicV1s { - if err := t.OffsetCommitInTopicV1s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitRequestV1) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerGroupID = string(b) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ConsumerGroupGenerationID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerID = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInTopicV1s = make([]OffsetCommitInTopicV1, int(l)) - for i := range t.OffsetCommitInTopicV1s { - if err := t.OffsetCommitInTopicV1s[i].Unmarshal(r); err != nil { - return err - } - } +func (t *OffsetCommitRequestV0) Unmarshal(r *Reader) { + t.ConsumerGroupID = string(r.ReadString()) + t.OffsetCommitInTopicV0s = make([]OffsetCommitInTopicV0, int(r.ReadInt32())) + for i := range t.OffsetCommitInTopicV0s { + t.OffsetCommitInTopicV0s[i].Unmarshal(r) } - return nil -} - -func (t *OffsetCommitInTopicV1) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.OffsetCommitInPartitionV1s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInPartitionV1s { - if err := t.OffsetCommitInPartitionV1s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitInTopicV1) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInPartitionV1s = make([]OffsetCommitInPartitionV1, int(l)) - for i := range t.OffsetCommitInPartitionV1s { - if err := t.OffsetCommitInPartitionV1s[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil } -func (t *OffsetCommitInPartitionV1) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err +func (t *OffsetCommitInTopicV0) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.OffsetCommitInPartitionV0s))) + for i := range t.OffsetCommitInPartitionV0s { + t.OffsetCommitInPartitionV0s[i].Marshal(w) } - if _, err := w.Write([]byte{byte(t.TimeStamp >> 56), byte(t.TimeStamp >> 48), byte(t.TimeStamp >> 40), byte(t.TimeStamp) >> 32, byte(t.TimeStamp >> 24), byte(t.TimeStamp >> 16), byte(t.TimeStamp >> 8), byte(t.TimeStamp)}); err != nil { - return err - } - { - l := int16(len(t.Metadata)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.Metadata)); err != nil { - return err - } - } - return nil } -func (t *OffsetCommitInPartitionV1) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.TimeStamp = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Metadata = string(b) - } - return nil -} - -func (t *OffsetCommitRequestV2) Marshal(w io.Writer) error { - { - l := int16(len(t.ConsumerGroup)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerGroup)); err != nil { - return err - } - } - if _, err := w.Write([]byte{byte(t.ConsumerGroupGenerationID >> 24), byte(t.ConsumerGroupGenerationID >> 16), byte(t.ConsumerGroupGenerationID >> 8), byte(t.ConsumerGroupGenerationID)}); err != nil { - return err - } - { - l := int16(len(t.ConsumerID)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerID)); err != nil { - return err - } - } - if _, err := w.Write([]byte{byte(t.RetentionTime >> 56), byte(t.RetentionTime >> 48), byte(t.RetentionTime >> 40), byte(t.RetentionTime) >> 32, byte(t.RetentionTime >> 24), byte(t.RetentionTime >> 16), byte(t.RetentionTime >> 8), byte(t.RetentionTime)}); err != nil { - return err - } - { - l := int32(len(t.OffsetCommitInTopicV2s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInTopicV2s { - if err := t.OffsetCommitInTopicV2s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitRequestV2) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerGroup = string(b) - } - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ConsumerGroupGenerationID = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerID = string(b) +func (t *OffsetCommitInTopicV0) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetCommitInPartitionV0s = make([]OffsetCommitInPartitionV0, int(r.ReadInt32())) + for i := range t.OffsetCommitInPartitionV0s { + t.OffsetCommitInPartitionV0s[i].Unmarshal(r) } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.RetentionTime = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInTopicV2s = make([]OffsetCommitInTopicV2, int(l)) - for i := range t.OffsetCommitInTopicV2s { - if err := t.OffsetCommitInTopicV2s[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitInTopicV2) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.OffsetCommitInPartitionV2s)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetCommitInPartitionV2s { - if err := t.OffsetCommitInPartitionV2s[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitInTopicV2) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetCommitInPartitionV2s = make([]OffsetCommitInPartitionV2, int(l)) - for i := range t.OffsetCommitInPartitionV2s { - if err := t.OffsetCommitInPartitionV2s[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil } -func (t *OffsetCommitInPartitionV2) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err - } - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err - } - { - l := int16(len(t.Metadata)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.Metadata)); err != nil { - return err - } - } - return nil +func (t *OffsetCommitInPartitionV0) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.Offset) + w.WriteString(string(t.Metadata)) } -func (t *OffsetCommitInPartitionV2) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) - } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Metadata = string(b) - } - return nil -} - -func (t *OffsetCommitResponse) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetCommitResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]ErrorInTopic, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *ErrorInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } - } - { - l := int32(len(t.ErrorInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.ErrorInPartitions { - if err := t.ErrorInPartitions[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *ErrorInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) - } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.ErrorInPartitions = make([]ErrorInPartition, int(l)) - for i := range t.ErrorInPartitions { - if err := t.ErrorInPartitions[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil +func (t *OffsetCommitInPartitionV0) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.Offset = r.ReadInt64() + t.Metadata = string(r.ReadString()) } -func (t *ErrorInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err +func (t *OffsetCommitRequestV1) Marshal(w *Writer) { + w.WriteString(string(t.ConsumerGroupID)) + w.WriteInt32(t.ConsumerGroupGenerationID) + w.WriteString(string(t.ConsumerID)) + w.WriteInt32(int32(len(t.OffsetCommitInTopicV1s))) + for i := range t.OffsetCommitInTopicV1s { + t.OffsetCommitInTopicV1s[i].Marshal(w) } - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err - } - return nil } -func (t *ErrorInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) - } - return nil -} - -func (t *OffsetFetchRequest) Marshal(w io.Writer) error { - { - l := int16(len(t.ConsumerGroup)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.ConsumerGroup)); err != nil { - return err - } - } - { - l := int32(len(t.PartitionInTopics)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.PartitionInTopics { - if err := t.PartitionInTopics[i].Marshal(w); err != nil { - return err - } - } - } - return nil -} - -func (t *OffsetFetchRequest) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.ConsumerGroup = string(b) +func (t *OffsetCommitRequestV1) Unmarshal(r *Reader) { + t.ConsumerGroupID = string(r.ReadString()) + t.ConsumerGroupGenerationID = r.ReadInt32() + t.ConsumerID = string(r.ReadString()) + t.OffsetCommitInTopicV1s = make([]OffsetCommitInTopicV1, int(r.ReadInt32())) + for i := range t.OffsetCommitInTopicV1s { + t.OffsetCommitInTopicV1s[i].Unmarshal(r) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.PartitionInTopics = make([]PartitionInTopic, int(l)) - for i := range t.PartitionInTopics { - if err := t.PartitionInTopics[i].Unmarshal(r); err != nil { - return err - } - } - } - return nil -} - -func (t *PartitionInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } +} + +func (t *OffsetCommitInTopicV1) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.OffsetCommitInPartitionV1s))) + for i := range t.OffsetCommitInPartitionV1s { + t.OffsetCommitInPartitionV1s[i].Marshal(w) } - { - l := int32(len(t.Partitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.Partitions { - if _, err := w.Write([]byte{byte(t.Partitions[i] >> 24), byte(t.Partitions[i] >> 16), byte(t.Partitions[i] >> 8), byte(t.Partitions[i])}); err != nil { - return err - } - } +} + +func (t *OffsetCommitInTopicV1) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetCommitInPartitionV1s = make([]OffsetCommitInPartitionV1, int(r.ReadInt32())) + for i := range t.OffsetCommitInPartitionV1s { + t.OffsetCommitInPartitionV1s[i].Unmarshal(r) } - return nil -} - -func (t *PartitionInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) +} + +func (t *OffsetCommitInPartitionV1) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.Offset) + w.WriteInt64(t.TimeStamp) + w.WriteString(string(t.Metadata)) +} + +func (t *OffsetCommitInPartitionV1) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.Offset = r.ReadInt64() + t.TimeStamp = r.ReadInt64() + t.Metadata = string(r.ReadString()) +} + +func (t *OffsetCommitRequestV2) Marshal(w *Writer) { + w.WriteString(string(t.ConsumerGroup)) + w.WriteInt32(t.ConsumerGroupGenerationID) + w.WriteString(string(t.ConsumerID)) + w.WriteInt64(t.RetentionTime) + w.WriteInt32(int32(len(t.OffsetCommitInTopicV2s))) + for i := range t.OffsetCommitInTopicV2s { + t.OffsetCommitInTopicV2s[i].Marshal(w) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.Partitions = make([]int32, int(l)) - for i := range t.Partitions { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partitions[i] = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) - } - } +} + +func (t *OffsetCommitRequestV2) Unmarshal(r *Reader) { + t.ConsumerGroup = string(r.ReadString()) + t.ConsumerGroupGenerationID = r.ReadInt32() + t.ConsumerID = string(r.ReadString()) + t.RetentionTime = r.ReadInt64() + t.OffsetCommitInTopicV2s = make([]OffsetCommitInTopicV2, int(r.ReadInt32())) + for i := range t.OffsetCommitInTopicV2s { + t.OffsetCommitInTopicV2s[i].Unmarshal(r) } - return nil -} - -func (t *OffsetFetchResponse) Marshal(w io.Writer) error { - { - l := int32(len((*t))) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range *t { - if err := (*t)[i].Marshal(w); err != nil { - return err - } - } +} + +func (t *OffsetCommitInTopicV2) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.OffsetCommitInPartitionV2s))) + for i := range t.OffsetCommitInPartitionV2s { + t.OffsetCommitInPartitionV2s[i].Marshal(w) } - return nil -} - -func (t *OffsetFetchResponse) Unmarshal(r io.Reader) error { - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - (*t) = make([]OffsetMetadataInTopic, int(l)) - for i := range *t { - if err := (*t)[i].Unmarshal(r); err != nil { - return err - } - } +} + +func (t *OffsetCommitInTopicV2) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetCommitInPartitionV2s = make([]OffsetCommitInPartitionV2, int(r.ReadInt32())) + for i := range t.OffsetCommitInPartitionV2s { + t.OffsetCommitInPartitionV2s[i].Unmarshal(r) } - return nil -} - -func (t *OffsetMetadataInTopic) Marshal(w io.Writer) error { - { - l := int16(len(t.TopicName)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.TopicName)); err != nil { - return err - } +} + +func (t *OffsetCommitInPartitionV2) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.Offset) + w.WriteString(string(t.Metadata)) +} + +func (t *OffsetCommitInPartitionV2) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.Offset = r.ReadInt64() + t.Metadata = string(r.ReadString()) +} + +func (t *OffsetCommitResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - { - l := int32(len(t.OffsetMetadataInPartitions)) - if _, err := w.Write([]byte{byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)}); err != nil { - return err - } - for i := range t.OffsetMetadataInPartitions { - if err := t.OffsetMetadataInPartitions[i].Marshal(w); err != nil { - return err - } - } +} + +func (t *OffsetCommitResponse) Unmarshal(r *Reader) { + (*t) = make([]ErrorInTopic, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - return nil -} - -func (t *OffsetMetadataInTopic) Unmarshal(r io.Reader) error { - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.TopicName = string(b) +} + +func (t *ErrorInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.ErrorInPartitions))) + for i := range t.ErrorInPartitions { + t.ErrorInPartitions[i].Marshal(w) } - { - var lb [4]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int32(lb[0])<<24 | int32(lb[1])<<16 | int32(lb[2])<<8 | int32(lb[3]) - t.OffsetMetadataInPartitions = make([]OffsetMetadataInPartition, int(l)) - for i := range t.OffsetMetadataInPartitions { - if err := t.OffsetMetadataInPartitions[i].Unmarshal(r); err != nil { - return err - } - } +} + +func (t *ErrorInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.ErrorInPartitions = make([]ErrorInPartition, int(r.ReadInt32())) + for i := range t.ErrorInPartitions { + t.ErrorInPartitions[i].Unmarshal(r) } - return nil } -func (t *OffsetMetadataInPartition) Marshal(w io.Writer) error { - if _, err := w.Write([]byte{byte(t.Partition >> 24), byte(t.Partition >> 16), byte(t.Partition >> 8), byte(t.Partition)}); err != nil { - return err +func (t *ErrorInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt16(t.ErrorCode) +} + +func (t *ErrorInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.ErrorCode = r.ReadInt16() +} + +func (t *OffsetFetchRequest) Marshal(w *Writer) { + w.WriteString(string(t.ConsumerGroup)) + w.WriteInt32(int32(len(t.PartitionInTopics))) + for i := range t.PartitionInTopics { + t.PartitionInTopics[i].Marshal(w) } - if _, err := w.Write([]byte{byte(t.Offset >> 56), byte(t.Offset >> 48), byte(t.Offset >> 40), byte(t.Offset) >> 32, byte(t.Offset >> 24), byte(t.Offset >> 16), byte(t.Offset >> 8), byte(t.Offset)}); err != nil { - return err +} + +func (t *OffsetFetchRequest) Unmarshal(r *Reader) { + t.ConsumerGroup = string(r.ReadString()) + t.PartitionInTopics = make([]PartitionInTopic, int(r.ReadInt32())) + for i := range t.PartitionInTopics { + t.PartitionInTopics[i].Unmarshal(r) } - { - l := int16(len(t.Metadata)) - if _, err := w.Write([]byte{byte(l >> 8), byte(l)}); err != nil { - return err - } - if _, err := w.Write([]byte(t.Metadata)); err != nil { - return err - } +} + +func (t *PartitionInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.Partitions))) + for i := range t.Partitions { + w.WriteInt32(t.Partitions[i]) } - if _, err := w.Write([]byte{byte(t.ErrorCode >> 8), byte(t.ErrorCode)}); err != nil { - return err +} + +func (t *PartitionInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.Partitions = make([]int32, int(r.ReadInt32())) + for i := range t.Partitions { + t.Partitions[i] = r.ReadInt32() } - return nil } -func (t *OffsetMetadataInPartition) Unmarshal(r io.Reader) error { - { - var b [4]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Partition = int32(b[0])<<24 | int32(b[1])<<16 | int32(b[2])<<8 | int32(b[3]) +func (t *OffsetFetchResponse) Marshal(w *Writer) { + w.WriteInt32(int32(len((*t)))) + for i := range *t { + (*t)[i].Marshal(w) } - { - var b [8]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.Offset = int64(b[0])<<56 | int64(b[1])<<48 | int64(b[2])<<40 | int64(b[3])<<32 | int64(b[4])<<24 | int64(b[5])<<16 | int64(b[6])<<8 | int64(b[7]) +} + +func (t *OffsetFetchResponse) Unmarshal(r *Reader) { + (*t) = make([]OffsetMetadataInTopic, int(r.ReadInt32())) + for i := range *t { + (*t)[i].Unmarshal(r) } - { - var lb [2]byte - if _, err := r.Read(lb[:]); err != nil { - return err - } - l := int16(lb[0])<<8 | int16(lb[1]) - b := make([]byte, l) - if _, err := r.Read(b); err != nil { - return err - } - t.Metadata = string(b) +} + +func (t *OffsetMetadataInTopic) Marshal(w *Writer) { + w.WriteString(string(t.TopicName)) + w.WriteInt32(int32(len(t.OffsetMetadataInPartitions))) + for i := range t.OffsetMetadataInPartitions { + t.OffsetMetadataInPartitions[i].Marshal(w) } - { - var b [2]byte - if _, err := r.Read(b[:]); err != nil { - return err - } - t.ErrorCode = int16(b[0])<<8 | int16(b[1]) +} + +func (t *OffsetMetadataInTopic) Unmarshal(r *Reader) { + t.TopicName = string(r.ReadString()) + t.OffsetMetadataInPartitions = make([]OffsetMetadataInPartition, int(r.ReadInt32())) + for i := range t.OffsetMetadataInPartitions { + t.OffsetMetadataInPartitions[i].Unmarshal(r) } - return nil +} + +func (t *OffsetMetadataInPartition) Marshal(w *Writer) { + w.WriteInt32(t.Partition) + w.WriteInt64(t.Offset) + w.WriteString(string(t.Metadata)) + w.WriteInt16(t.ErrorCode) +} + +func (t *OffsetMetadataInPartition) Unmarshal(r *Reader) { + t.Partition = r.ReadInt32() + t.Offset = r.ReadInt64() + t.Metadata = string(r.ReadString()) + t.ErrorCode = r.ReadInt16() } diff --git a/proto/pre.go b/proto/pre.go index a830aa2..6a54463 100644 --- a/proto/pre.go +++ b/proto/pre.go @@ -1,15 +1,129 @@ package proto -import ( - "errors" - "io" -) +import "errors" var ( - errNilUnmarshaler = errors.New("nil unmarshaler") + errUnexpectedEOF = errors.New("unexpected EOF") ) type T interface { - Marshal(io.Writer) error - Unmarshal(io.Reader) error + Marshal(*Writer) + Unmarshal(*Reader) +} + +type Writer struct { + B []byte +} + +type Reader struct { + B []byte + Offset int + Err error +} + +func (w *Writer) WriteInt8(i int8) { + w.B = append(w.B, byte(i)) +} + +func (r *Reader) ReadInt8() int8 { + if r.Err != nil { + return 0 + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return 0 + } + i := r.Offset + r.Offset++ + return int8(r.B[i]) +} + +func (w *Writer) WriteInt16(i int16) { + w.B = append(w.B, byte(i>>8), byte(i)) +} + +func (r *Reader) ReadInt16() int16 { + if r.Err != nil { + return 0 + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return 0 + } + i := r.Offset + r.Offset += 2 + return int16(r.B[i])<<8 | int16(r.B[i+1]) +} + +func (w *Writer) WriteInt32(i int32) { + w.B = append(w.B, byte(i>>24), byte(i>>16), byte(i>>8), byte(i)) +} + +func (r *Reader) ReadInt32() int32 { + if r.Err != nil { + return 0 + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return 0 + } + i := r.Offset + r.Offset += 4 + return int32(r.B[i])<<24 | int32(r.B[i+1])<<16 | int32(r.B[i+2])<<8 | int32(r.B[i+3]) +} + +func (w *Writer) WriteInt64(i int64) { + w.B = append(w.B, byte(i>>56), byte(i>>48), byte(i>>40), byte(i>>32), byte(i>>24), byte(i>>16), byte(i>>8), byte(i)) +} + +func (r *Reader) ReadInt64() int64 { + if r.Err != nil { + return 0 + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return 0 + } + i := r.Offset + r.Offset += 8 + return int64(r.B[i])<<56 | int64(r.B[i+1])<<48 | int64(r.B[i+2])<<40 | int64(r.B[i+3])<<32 | + int64(r.B[i+4])<<24 | int64(r.B[i+5])<<16 | int64(r.B[i+6])<<8 | int64(r.B[i+7]) +} + +func (w *Writer) WriteString(s string) { + w.WriteInt16(int16(len(s))) + w.B = append(w.B, s...) +} + +func (r *Reader) ReadString() string { + if r.Err != nil { + return "" + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return "" + } + l := int(r.ReadInt16()) + i := r.Offset + r.Offset += l + return string(r.B[i : i+l]) +} + +func (w *Writer) WriteBytes(bs []byte) { + w.WriteInt32(int32(len(bs))) + w.B = append(w.B, bs...) +} + +func (r *Reader) ReadBytes() []byte { + if r.Err != nil { + return nil + } + if r.Offset >= len(r.B) { + r.Err = errUnexpectedEOF + return nil + } + l := int(r.ReadInt32()) + i := r.Offset + r.Offset += l + return r.B[i : i+l] } diff --git a/spec/gen/marshal.go b/spec/gen/marshal.go index 7301ac7..ac7db23 100644 --- a/spec/gen/marshal.go +++ b/spec/gen/marshal.go @@ -28,7 +28,7 @@ func genMarshalFunc(w io.Writer, decl *gengo.TypeDecl) { if t.Kind == gengo.IdentKind && t.Ident == "T" { return } - fpl(w, "func (t *%s) Marshal(w io.Writer) error {", decl.Name) + fpl(w, "func (t *%s) Marshal(w *Writer) {", decl.Name) switch t.Kind { case gengo.StructKind: for _, f := range t.Fields { @@ -45,7 +45,6 @@ func genMarshalFunc(w io.Writer, decl *gengo.TypeDecl) { default: fpl(w, "// type %s, %v", decl.Name, decl.Type) } - fpl(w, "return nil") fpl(w, "}") } @@ -54,7 +53,7 @@ func genUnmarshalFunc(w io.Writer, decl *gengo.TypeDecl) { if t.Kind == gengo.IdentKind && t.Ident == "T" { return } - fpl(w, "func (t *%s) Unmarshal(r io.Reader) error {", decl.Name) + fpl(w, "func (t *%s) Unmarshal(r *Reader) {", decl.Name) switch t.Kind { case gengo.StructKind: for _, f := range t.Fields { @@ -72,7 +71,6 @@ func genUnmarshalFunc(w io.Writer, decl *gengo.TypeDecl) { default: fpl(w, "// type %s, %v", decl.Name, decl.Type) } - fpl(w, "return nil") fpl(w, "}") } @@ -89,24 +87,14 @@ func marshalValue(w io.Writer, name string, kind gengo.Kind, typ string) { case "int8": marshalInt(w, name, 8) case "string": - fpl(w, "{") - fpl(w, "l := int16(len(%s))", name) - marshalInt(w, "l", 16) - writeBytes(w, fmt.Sprintf("[]byte(%s)", name)) - fpl(w, "}") + fpl(w, "w.WriteString(string(%s))", name) case "[]byte": - fpl(w, "{") - fpl(w, "l := int32(len(%s))", name) - marshalInt(w, "l", 32) - writeBytes(w, fmt.Sprintf("%s", name)) - fpl(w, "}") + fpl(w, "w.WriteBytes(%s)", name) default: marshalMarshaler(w, name) } case gengo.ArrayKind: - fpl(w, "{") - fpl(w, "l := int32(len(%s))", name) - marshalInt(w, "l", 32) + marshalInt(w, fmt.Sprintf("int32(len(%s))", name), 32) fpl(w, "for i := range %s {", name) switch typ { case "int8", "int16", "int32", "int64", "string": @@ -115,14 +103,12 @@ func marshalValue(w io.Writer, name string, kind gengo.Kind, typ string) { marshalMarshaler(w, name+"[i]") } fpl(w, "}") - fpl(w, "}") default: fpl(w, "// value %s %v", name, kind) } } func unmarshalValue(w io.Writer, name string, kind gengo.Kind, typ, declType string) { - fpl(w, "{") switch kind { case gengo.IdentKind: switch typ { @@ -135,19 +121,14 @@ func unmarshalValue(w io.Writer, name string, kind gengo.Kind, typ, declType str case "int8": unmarshalInt(w, name, "b", 8) case "string": - unmarshalInt(w, "l:", "lb", 16) - readBytes(w, "b", "l") - fpl(w, "%s = %s(b)", name, declType) + fpl(w, "%s = %s(r.ReadString())", name, declType) case "[]byte": - unmarshalInt(w, "l:", "lb", 32) - readBytes(w, "b", "l") - fpl(w, "%s = b", name) + fpl(w, "%s = r.ReadBytes()", name) default: unmarshalUnmarshaler(w, name, typ) } case gengo.ArrayKind: - unmarshalInt(w, "l:", "lb", 32) - fpl(w, "%s = make([]%s, int(l))", name, typ) + fpl(w, "%s = make([]%s, int(r.ReadInt32()))", name, typ) fpl(w, "for i := range %s {", name) switch typ { case "int8", "int16", "int32", "int64", "string": @@ -159,28 +140,22 @@ func unmarshalValue(w io.Writer, name string, kind gengo.Kind, typ, declType str default: fpl(w, "// value %s %v", name, kind) } - fpl(w, "}") } func marshalMarshaler(w io.Writer, marshaler string) { - fpl(w, "if err := %s.Marshal(w); err != nil {", marshaler) - fpl(w, "return err") - fpl(w, "}") + fpl(w, "%s.Marshal(w)", marshaler) } func unmarshalUnmarshaler(w io.Writer, unmarshaler, typ string) { - fpl(w, "if err := %s.Unmarshal(r); err != nil {", unmarshaler) - fpl(w, "return err") - fpl(w, "}") + fpl(w, "%s.Unmarshal(r)", unmarshaler) } func marshalInt(w io.Writer, name string, bit int) { - writeBytes(w, intToBytes(name, bit)) + fpl(w, "w.WriteInt%d(%s)", bit, name) } func unmarshalInt(w io.Writer, name string, bufName string, bit int) { - readByteArray(w, bufName, bit) - fpl(w, "%s=%s", name, bytesToInt(bufName, bit)) + fpl(w, "%s=r.ReadInt%d()", name, bit) } func writeBytes(w io.Writer, bytes string) {