Skip to content

Commit

Permalink
finish
Browse files Browse the repository at this point in the history
  • Loading branch information
tjons committed Jun 27, 2024
1 parent c7e0f70 commit ec9816f
Show file tree
Hide file tree
Showing 5 changed files with 814 additions and 824 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/solo-io/protoc-gen-ext/module/equal"
"github.com/solo-io/protoc-gen-ext/module/hash"
"github.com/solo-io/protoc-gen-ext/module/merge"
"github.com/solo-io/protoc-gen-ext/module/uniquehash"
)

func main() {
Expand All @@ -21,6 +22,7 @@ func main() {
equal.Equal(),
merge.Merge(),
clone.Clone(),
uniquehash.Hash(),
).RegisterPostProcessor(
pgsgo.GoFmt(),
).Render()
Expand Down
4 changes: 2 additions & 2 deletions module/uniquehash/uniquehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
pgsgo "github.com/lyft/protoc-gen-star/lang/go"
"github.com/solo-io/protoc-gen-ext/extproto"
"github.com/solo-io/protoc-gen-ext/templates"
"github.com/solo-io/protoc-gen-ext/templates/hash"
"github.com/solo-io/protoc-gen-ext/templates/uniquehash"
)

const (
Expand All @@ -28,7 +28,7 @@ func (m *HashModule) Name() string { return hasherName }

func (m *HashModule) Execute(targets map[string]pgs.File, pkgs map[string]pgs.Package) []pgs.Artifact {
// Process file-level templates
tpl := templates.Template(m.Parameters(), hash.Register)
tpl := templates.Template(m.Parameters(), uniquehash.Register)

for _, f := range targets {
var hashAll bool
Expand Down
4 changes: 4 additions & 0 deletions templates/hash/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package hash

const msgTpl = `
// Hash function
//
// Deprecated: due to hashing implemention only using field values. The omission
// of the field name in the hash calculation can lead to hash collisions.
// Prefer the HashUnique function instead.
func (m {{ (msgTyp .).Pointer }}) Hash(hasher hash.Hash64) (uint64, error) {
if m == nil { return 0, nil }
if hasher == nil { hasher = fnv.New64() }
Expand Down
Loading

0 comments on commit ec9816f

Please sign in to comment.