Skip to content
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

Use protocolbuffers instead of gogo #895

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ require (
github.com/DataDog/zstd v1.5.0
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b
github.com/davecgh/go-spew v1.1.1
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.1.2
github.com/klauspost/compress v1.14.4
github.com/linkedin/goavro/v2 v2.9.8
Expand All @@ -27,4 +25,5 @@ require (
go.uber.org/atomic v1.7.0
golang.org/x/mod v0.5.1
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602
google.golang.org/protobuf v1.26.0
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
Expand Down Expand Up @@ -419,7 +418,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
Expand Down
4 changes: 1 addition & 3 deletions integration-tests/pb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
# under the License.
#

pkg=pb
protoc --go_out=import_path=${pkg}:. hello.proto

protoc --go_out=. --go_opt=paths=source_relative hello.proto
180 changes: 124 additions & 56 deletions integration-tests/pb/hello.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions integration-tests/pb/hello.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
syntax = "proto3";
package prototest;

option go_package = "./pb";

message Test {
int32 num = 1;
string msf = 2;
Expand Down
2 changes: 1 addition & 1 deletion pulsar/consumer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"sync/atomic"
"time"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/apache/pulsar-client-go/pulsar/crypto"
"github.com/apache/pulsar-client-go/pulsar/internal"
Expand Down
2 changes: 1 addition & 1 deletion pulsar/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import (
"github.com/apache/pulsar-client-go/pulsar/internal"
pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
plog "github.com/apache/pulsar-client-go/pulsar/log"
"github.com/gogo/protobuf/proto"
"github.com/google/uuid"
"github.com/pierrec/lz4"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pulsar/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

pkgerrors "github.com/pkg/errors"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/apache/pulsar-client-go/pulsar/internal"
pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
Expand Down
2 changes: 1 addition & 1 deletion pulsar/impl_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync"
"time"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
)
Expand Down
2 changes: 1 addition & 1 deletion pulsar/internal/batch_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"bytes"
"time"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/apache/pulsar-client-go/pulsar/internal/compression"
"github.com/apache/pulsar-client-go/pulsar/internal/crypto"
Expand Down
10 changes: 5 additions & 5 deletions pulsar/internal/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"errors"
"fmt"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/apache/pulsar-client-go/pulsar/internal/compression"
"github.com/apache/pulsar-client-go/pulsar/internal/crypto"
Expand Down Expand Up @@ -226,11 +226,11 @@ func baseCommand(cmdType pb.BaseCommand_Type, msg proto.Message) *pb.BaseCommand
}

func addSingleMessageToBatch(wb Buffer, smm *pb.SingleMessageMetadata, payload []byte) {
metadataSize := uint32(smm.Size())
metadataSize := uint32(proto.Size(smm))
wb.WriteUint32(metadataSize)

wb.ResizeIfNeeded(metadataSize)
_, err := smm.MarshalToSizedBuffer(wb.WritableSlice()[:metadataSize])
err := MarshalToSizedBuffer(smm, wb.WritableSlice()[:metadataSize])
if err != nil {
panic(fmt.Sprintf("Protobuf serialization error: %v", err))
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func serializeMessage(wb Buffer,
// Write cmd
wb.WriteUint32(cmdSize)
wb.ResizeIfNeeded(cmdSize)
_, err = cmdSend.MarshalToSizedBuffer(wb.WritableSlice()[:cmdSize])
err = MarshalToSizedBuffer(cmdSend, wb.WritableSlice()[:cmdSize])
if err != nil {
panic(fmt.Sprintf("Protobuf error when serializing cmdSend: %v", err))
}
Expand All @@ -297,7 +297,7 @@ func serializeMessage(wb Buffer,
metadataStartIdx := wb.WriterIndex()
wb.WriteUint32(msgMetadataSize)
wb.ResizeIfNeeded(msgMetadataSize)
_, err = msgMetadata.MarshalToSizedBuffer(wb.WritableSlice()[:msgMetadataSize])
err = MarshalToSizedBuffer(msgMetadata, wb.WritableSlice()[:msgMetadataSize])
if err != nil {
panic(fmt.Sprintf("Protobuf error when serializing msgMetadata: %v", err))
}
Expand Down
6 changes: 3 additions & 3 deletions pulsar/internal/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sync/atomic"
"time"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

"github.com/apache/pulsar-client-go/pulsar/internal/auth"
pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
Expand Down Expand Up @@ -486,7 +486,7 @@ func (c *connection) internalWriteData(data Buffer) {
func (c *connection) writeCommand(cmd *pb.BaseCommand) {
// Wire format
// [FRAME_SIZE] [CMD_SIZE][CMD]
cmdSize := uint32(cmd.Size())
cmdSize := uint32(proto.Size(cmd))
frameSize := cmdSize + 4

c.writeBufferLock.Lock()
Expand All @@ -497,7 +497,7 @@ func (c *connection) writeCommand(cmd *pb.BaseCommand) {

c.writeBuffer.WriteUint32(cmdSize)
c.writeBuffer.ResizeIfNeeded(cmdSize)
_, err := cmd.MarshalToSizedBuffer(c.writeBuffer.WritableSlice()[:cmdSize])
err := MarshalToSizedBuffer(cmd, c.writeBuffer.WritableSlice()[:cmdSize])
if err != nil {
c.log.WithError(err).Error("Protobuf serialization error")
panic("Protobuf serialization error")
Expand Down
2 changes: 1 addition & 1 deletion pulsar/internal/connection_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"io"

pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"
)

type connectionReader struct {
Expand Down
2 changes: 1 addition & 1 deletion pulsar/internal/lookup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"net/url"

"github.com/gogo/protobuf/proto"
"google.golang.org/protobuf/proto"

pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
"github.com/apache/pulsar-client-go/pulsar/log"
Expand Down
Loading