Skip to content

Refactor: Refactor ClusterMetadataPayload interface #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions protocol/api/cluster_metadata_payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@
"github.com/codecrafters-io/kafka-tester/protocol/errors"
)

type ClusterMetadataPayload struct {
//lint:ignore U1000, these are not used in the codebase currently
type ClusterMetadataRecordValue struct {
FrameVersion int8
Type int8
Version int8
Data ClusterMetadataPayloadDataRecord
Data []byte
}

type ClusterMetadataPayloadDataRecord interface {
isPayloadRecord()
func (v ClusterMetadataRecordValue) Encode() []byte {
return []byte{}
}

type BeginTransactionRecord struct {
type BeginTransactionRecordValue struct {
Name string
}

func (b *BeginTransactionRecord) isPayloadRecord() {}
func (b *BeginTransactionRecordValue) Encode() []byte {
encoder := encoder.RealEncoder{}
encoder.Init(make([]byte, 4096))

encoder.PutUVarint(1) // taggedFieldCount
// Encode all the fields

encodedData := encoder.Bytes()[:encoder.Offset()]

return ClusterMetadataRecordValue{
FrameVersion: 1,
Type: 0,
Version: 0,
Data: encodedData,
}.Encode()
}

type EndTransactionRecord struct {
}
Expand Down Expand Up @@ -66,7 +82,7 @@
func (p *PartitionRecord) isPayloadRecord() {}

//lint:ignore U1000, these are not used in the codebase currently
func (p *ClusterMetadataPayload) Decode(data []byte) (err error) {

Check failure on line 85 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ClusterMetadataPayload

Check failure on line 85 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / test

undefined: ClusterMetadataPayload
partialDecoder := decoder.RealDecoder{}
partialDecoder.Init(data)

Expand All @@ -87,7 +103,7 @@

switch p.Type {
case 23:
beginTransactionRecord := &BeginTransactionRecord{}

Check failure on line 106 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / lint

undefined: BeginTransactionRecord

Check failure on line 106 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / test

undefined: BeginTransactionRecord
p.Data = beginTransactionRecord

taggedFieldCount, err := partialDecoder.GetUnsignedVarint()
Expand Down Expand Up @@ -265,7 +281,7 @@
return nil
}

func (p *ClusterMetadataPayload) Encode(pe *encoder.RealEncoder) {

Check failure on line 284 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ClusterMetadataPayload (compile)

Check failure on line 284 in protocol/api/cluster_metadata_payloads.go

View workflow job for this annotation

GitHub Actions / test

undefined: ClusterMetadataPayload
pe.PutInt8(p.FrameVersion)
pe.PutInt8(p.Type)
pe.PutInt8(p.Version)
Expand Down
Loading