Skip to content

Commit

Permalink
hashing repeated fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tjons committed Jun 21, 2024
1 parent 250417d commit 3cf802d
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 24 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GO_IMPORT:=$(subst $(space),,$(GO_IMPORT_SPACES))

.PHONY: generated-code
generated-code:
rm -rf tests/api/*.go
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./external --go_out="${EXT_IMPORT}:." extproto/ext.proto
PATH=$(DEPSGOBIN):$$PATH cp -r ${PACKAGE}/extproto/* extproto
PATH=$(DEPSGOBIN):$$PATH $(DEPSGOBIN)/protoc -I=. -I=./extproto -I=./external --go_out="." --ext_out="." tests/api/hello.proto
Expand Down
1 change: 1 addition & 0 deletions templates/hash/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"hash"
"hash/fnv"
"strconv"
"github.com/solo-io/protoc-gen-ext/pkg/hasher/hashstructure"
safe_hasher "github.com/solo-io/protoc-gen-ext/pkg/hasher"
Expand Down
8 changes: 7 additions & 1 deletion templates/hash/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ const mapTpl = `
`

const repeatedTpl = `
for _, v := range {{ .FieldAccessor }} {
if _, err = hasher.Write([]byte("{{ .FieldName }}")); err != nil {
return 0, err
}
for i, v := range {{ .FieldAccessor }} {
if _, err = hasher.Write([]byte(strconv.Itoa(i))); err != nil {
return 0, err
}
{{ .InnerTemplates.Value }}
}
`
29 changes: 29 additions & 0 deletions tests/api/hello.pb.clone.go

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

46 changes: 46 additions & 0 deletions tests/api/hello.pb.equal.go

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

110 changes: 91 additions & 19 deletions tests/api/hello.pb.go

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

75 changes: 72 additions & 3 deletions tests/api/hello.pb.hash.go

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

Loading

0 comments on commit 3cf802d

Please sign in to comment.