Skip to content

Commit

Permalink
refactor: CloneMessageVT returns a common CloneMessage interface
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 22, 2024
1 parent 2321621 commit 503e9d2
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 84 deletions.
2 changes: 2 additions & 0 deletions compiler/protogen/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var typesPackage = "github.com/aperturerobotics/protobuf-go-lite/types/"

var trimTypesPrefix = "google.golang.org/protobuf/types/"

var ProtobufGoLitePackage = GoImportPath("github.com/aperturerobotics/protobuf-go-lite")

func fixTypesPrefix(impPath GoImportPath) GoImportPath {
if strings.HasPrefix(string(impPath), trimTypesPrefix) {
impPath = GoImportPath(typesPackage + strings.TrimPrefix(string(impPath), trimTypesPrefix))
Expand Down
2 changes: 1 addition & 1 deletion features/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *clone) generateCloneMethodsForMessage(proto3 bool, message *protogen.Me
p.P(`}`)
p.P()

p.P(`func (m *`, ccTypeName, `) `, cloneMessageName, `() any {`)
p.P(`func (m *`, ccTypeName, `) `, cloneMessageName, `() `, p.QualifiedGoIdent(protogen.ProtobufGoLitePackage.Ident("CloneMessage")), ` {`)
p.P(`return m.`, cloneName, `()`)
p.P(`}`)
p.P()
Expand Down
10 changes: 10 additions & 0 deletions protobuf-go-lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ type Message interface {
Reset()
}

// CloneMessage is a message with a CloneMessage function.
type CloneMessage interface {
// Message extends the base message type.
Message
// CloneMessageVT clones the object.
CloneMessageVT() CloneMessage
}

// CloneVT is a message with a CloneVT function (VTProtobuf).
type CloneVT[T comparable] interface {
comparable
// CloneMessage is the non-generic clone interface.
CloneMessage
// CloneVT clones the object.
CloneVT() T
}
Expand Down
2 changes: 1 addition & 1 deletion testproto/disable-json/disable-json.pb.go

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

2 changes: 1 addition & 1 deletion testproto/maps/maps.pb.go

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

32 changes: 16 additions & 16 deletions testproto/proto2/scalars.pb.go

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

2 changes: 1 addition & 1 deletion testproto/proto3opt/opt.pb.go

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

12 changes: 6 additions & 6 deletions testproto/unsafe/unsafe.pb.go

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

2 changes: 1 addition & 1 deletion testproto/wkt/wkt.pb.go

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

Loading

0 comments on commit 503e9d2

Please sign in to comment.