Skip to content

Commit 5c0fd2f

Browse files
committed
Kafka 2.8.0 support
1 parent afed55e commit 5c0fd2f

39 files changed

+1629
-90
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
sudo: false
2-
1+
sudo: required
32
language: go
3+
dist: focal
44

55
go:
6-
- "1.15.x"
6+
- "1.16.x"
77

88
env:
99
global:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.15-alpine3.12 as builder
1+
FROM golang:1.16-alpine3.14 as builder
22
RUN apk add alpine-sdk ca-certificates
33

44
WORKDIR /go/src/github.com/grepplabs/kafka-proxy
@@ -9,7 +9,7 @@ ARG GOOS=linux
99
ARG GOARCH=amd64
1010
RUN make -e GOARCH=${GOARCH} -e GOOS=${GOOS} clean ${MAKE_TARGET}
1111

12-
FROM alpine:3.12
12+
FROM alpine:3.14
1313
RUN apk add --no-cache ca-certificates
1414

1515
COPY --from=builder /go/src/github.com/grepplabs/kafka-proxy/build /opt/kafka-proxy/bin

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
.PHONY: clean build all tag release
44

5+
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
6+
57
BINARY ?= kafka-proxy
68
SOURCES = $(shell find . -name '*.go' | grep -v /vendor/)
79
VERSION ?= $(shell git describe --tags --always --dirty)
810
GOPKGS = $(shell go list ./... | grep -v /vendor/)
911
BUILD_FLAGS ?=
1012
LDFLAGS ?= -X github.com/grepplabs/kafka-proxy/config.Version=$(VERSION) -w -s
11-
TAG ?= "v0.2.8"
13+
TAG ?= "v0.2.9"
1214
GOARCH ?= amd64
1315
GOOS ?= linux
1416

@@ -38,7 +40,7 @@ tag:
3840

3941
release: clean
4042
git push origin $(TAG)
41-
rm -rf ./dist
43+
rm -rf $(ROOT_DIR)/dist
4244
curl -sL https://git.io/goreleaser | bash
4345

4446
protoc.local-auth:
@@ -74,4 +76,4 @@ plugin.oidc-provider:
7476
all: build plugin.auth-user plugin.auth-ldap plugin.google-id-provider plugin.google-id-info plugin.unsecured-jwt-info plugin.unsecured-jwt-provider plugin.oidc-provider
7577

7678
clean:
77-
@rm -rf build
79+
rm -rf $(ROOT_DIR)/build

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## kafka-proxy
22
**Work in progress**
33

4-
[![Build Status](https://travis-ci.org/grepplabs/kafka-proxy.svg?branch=master)](https://travis-ci.org/grepplabs/kafka-proxy)
4+
[![Build Status](https://travis-ci.com/grepplabs/kafka-proxy.svg?branch=master)](https://travis-ci.com/grepplabs/kafka-proxy)
55
[![Docker Hub](https://img.shields.io/badge/docker-latest-blue.svg)](https://hub.docker.com/r/grepplabs/kafka-proxy)
66
[![Docker Pulls](https://img.shields.io/docker/pulls/grepplabs/kafka-proxy)](https://hub.docker.com/r/grepplabs/kafka-proxy)
77

@@ -36,11 +36,11 @@ See:
3636

3737
Linux
3838

39-
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.2.8/kafka-proxy-v0.2.8-linux-amd64.tar.gz | tar xz
39+
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.2.9/kafka-proxy-v0.2.9-linux-amd64.tar.gz | tar xz
4040

4141
macOS
4242

43-
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.2.8/kafka-proxy-v0.2.8-darwin-amd64.tar.gz | tar xz
43+
curl -Ls https://github.com/grepplabs/kafka-proxy/releases/download/v0.2.9/kafka-proxy-v0.2.9-darwin-amd64.tar.gz | tar xz
4444

4545
2. Move the binary in to your PATH.
4646

@@ -58,7 +58,7 @@ Docker images are available on [Docker Hub](https://hub.docker.com/r/grepplabs/k
5858
5959
You can launch a kafka-proxy container for trying it out with
6060
61-
docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.2.8 \
61+
docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.2.9 \
6262
server \
6363
--bootstrap-server-mapping "localhost:19092,0.0.0.0:30001" \
6464
--bootstrap-server-mapping "localhost:29092,0.0.0.0:30002" \
@@ -77,7 +77,7 @@ Docker images with precompiled plugins located in `/opt/kafka-proxy/bin/` are ta
7777
7878
You can launch a kafka-proxy container with auth-ldap plugin for trying it out with
7979
80-
docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.2.8-all \
80+
docker run --rm -p 30001-30003:30001-30003 grepplabs/kafka-proxy:v0.2.9-all \
8181
server \
8282
--bootstrap-server-mapping "localhost:19092,0.0.0.0:30001" \
8383
--bootstrap-server-mapping "localhost:29092,0.0.0.0:30002" \

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/grepplabs/kafka-proxy
22

3-
go 1.15
3+
go 1.16
44

55
require (
66
cloud.google.com/go v0.19.0 // indirect
@@ -12,6 +12,7 @@ require (
1212
github.com/go-ldap/ldap/v3 v3.2.3
1313
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
1414
github.com/golang/protobuf v1.4.2
15+
github.com/google/uuid v1.2.0
1516
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
1617
github.com/hashicorp/go-hclog v0.0.0-20180122232401-5bcb0f17e364
1718
github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874
@@ -46,6 +47,5 @@ require (
4647
google.golang.org/appengine v1.0.0 // indirect
4748
google.golang.org/genproto v0.0.0-20180316064809-f8c870359523 // indirect
4849
google.golang.org/grpc v1.10.0
49-
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225 // indirect
5050
gopkg.in/yaml.v2 v2.3.0 // indirect
5151
)

go.sum

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ github.com/cenkalti/backoff v1.1.0 h1:QnvVp8ikKCDWOsFheytRCoYWYPO/ObCTBGxT19Hc+y
1818
github.com/cenkalti/backoff v1.1.0/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
1919
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
2020
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
21-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2221
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2322
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2423
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -30,7 +29,6 @@ github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us
3029
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
3130
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
3231
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
33-
github.com/go-ldap/ldap v3.0.3+incompatible h1:HTeSZO8hWMS1Rgb2Ziku6b8a7qRIZZMHjsvuZyatzwk=
3432
github.com/go-ldap/ldap/v3 v3.2.3 h1:FBt+5w3q/vPVPb4eYMQSn+pOiz4zewPamYhlGMmc7yM=
3533
github.com/go-ldap/ldap/v3 v3.2.3/go.mod h1:iYS1MdmrmceOJ1QOTnRXrIs7i3kloqtmGQjRvjKpyMg=
3634
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
@@ -54,6 +52,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
5452
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
5553
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5654
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
55+
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
56+
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5757
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce h1:prjrVgOk2Yg6w+PflHoszQNLTUh4kaByUcEWM/9uin4=
5858
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
5959
github.com/hashicorp/go-hclog v0.0.0-20180122232401-5bcb0f17e364 h1:Q30cq6GgGiEGzz3jxQELCRfCoST5Cqqegs4WV4/u/uM=
@@ -73,7 +73,6 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
7373
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
7474
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
7575
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
76-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
7776
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
7877
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
7978
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -100,9 +99,7 @@ github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
10099
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
101100
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
102101
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
103-
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
104102
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
105-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
106103
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
107104
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
108105
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -124,7 +121,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
124121
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
125122
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
126123
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
127-
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
128124
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
129125
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
130126
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
@@ -151,9 +147,7 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
151147
github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0=
152148
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
153149
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
154-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
155150
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
156-
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
157151
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
158152
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
159153
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -175,11 +169,9 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
175169
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
176170
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
177171
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
178-
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
179172
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
180173
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
181174
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182-
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
183175
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
184176
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
185177
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@@ -202,15 +194,9 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
202194
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
203195
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
204196
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
205-
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225 h1:JBwmEvLfCqgPcIq8MjVMQxsF3LVL4XG/HH0qiG0+IFY=
206-
gopkg.in/asn1-ber.v1 v1.0.0-20170511165959-379148ca0225/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw=
207-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
208197
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
209198
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
210199
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
211-
gopkg.in/ldap.v2 v2.5.1 h1:wiu0okdNfjlBzg6UWvd1Hn8Y+Ux17/u/4nlk4CQr6tU=
212-
gopkg.in/ldap.v2 v2.5.1/go.mod h1:oI0cpe/D7HRtBQl8aTg+ZmzFUAvu4lsv3eLXMLGFxWk=
213-
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
214200
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
215201
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
216202
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

proxy/processor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
apiKeyApiApiVersions = int16(18)
2222

2323
minRequestApiKey = int16(0) // 0 - Produce
24-
maxRequestApiKey = int16(100) // so far 42 is the last (reserve some for the feature)
24+
maxRequestApiKey = int16(120) // so far 67 is the last (reserve some for the feature)
2525
)
2626

2727
var (

proxy/processor_default.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (handler *DefaultRequestHandler) mustReply(requestKeyVersion *protocol.Requ
159159
return false, nil, err
160160
}
161161

162-
case 3, 4, 5, 6, 7, 8:
162+
case 3, 4, 5, 6, 7, 8, 9:
163163
// CorrelationID + ClientID
164164
if err = acksReader.ReadAndDiscardHeaderV1Part(reader); err != nil {
165165
return false, nil, err

proxy/protocol/encoder_decoder_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package protocol
22

33
import (
44
"bytes"
5+
"github.com/google/uuid"
56
"github.com/pkg/errors"
67
"math"
78
"math/rand"
@@ -170,6 +171,34 @@ func TestEncodeDecodeCompactNullableString(t *testing.T) {
170171
}
171172
}
172173

174+
func TestEncodeDecodeUUID(t *testing.T) {
175+
values := make([]uuid.UUID, 0)
176+
for i := 0; i < 10; i++ {
177+
value := uuid.New()
178+
values = append(values, value)
179+
}
180+
request := &UUIDsHolder{
181+
values: values,
182+
}
183+
buf, err := Encode(request)
184+
if err != nil {
185+
t.Fatal(err)
186+
}
187+
response := &UUIDsHolder{}
188+
err = Decode(buf, response)
189+
if err != nil {
190+
t.Fatal(err)
191+
}
192+
if len(request.values) != len(response.values) {
193+
t.Fatalf("Values array lengths differ: expected %v, actual %v", request.values, response.values)
194+
}
195+
for i := range request.values {
196+
if request.values[i] != response.values[i] {
197+
t.Fatalf("Values differ: index %d, expected %v, actual %v", i, request.values[i], response.values[i])
198+
}
199+
}
200+
}
201+
173202
func TestEncodeDecodeCompactArray(t *testing.T) {
174203
compactArray := &CompactArray{Name: "strings", Ty: TypeStr}
175204
tt := []struct {
@@ -587,3 +616,32 @@ func RandStringRunes(n int) string {
587616
}
588617
return string(b)
589618
}
619+
620+
type UUIDsHolder struct {
621+
values []uuid.UUID
622+
}
623+
624+
func (r *UUIDsHolder) encode(pe packetEncoder) (err error) {
625+
for _, value := range r.values {
626+
err = pe.putUUID(value)
627+
if err != nil {
628+
return err
629+
}
630+
}
631+
return
632+
}
633+
634+
func (r *UUIDsHolder) decode(pd packetDecoder) (err error) {
635+
r.values = make([]uuid.UUID, 0)
636+
var value uuid.UUID
637+
for ok := true; ok; ok = pd.remaining() > 0 {
638+
if value, err = pd.getUUID(); err != nil {
639+
return err
640+
}
641+
r.values = append(r.values, value)
642+
}
643+
if pd.remaining() != 0 {
644+
return errors.Errorf("remaining bytes %d", pd.remaining())
645+
}
646+
return
647+
}

proxy/protocol/packet_decoder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package protocol
22

3+
import "github.com/google/uuid"
4+
35
// PacketDecoder is the interface providing helpers for reading with Kafka's encoding rules.
46
// Types implementing Decoder only need to worry about calling methods like GetString,
57
// not about how a string is represented in Kafka.
@@ -14,6 +16,7 @@ type packetDecoder interface {
1416
getBool() (bool, error)
1517

1618
getBytes() ([]byte, error)
19+
getUUID() (uuid.UUID, error)
1720
getString() (string, error)
1821
getNullableString() (*string, error)
1922
getInt32Array() ([]int32, error)

0 commit comments

Comments
 (0)