https://github.com/stackb/protoreflecthash
Reimplementation of https://github.com/deepmind/objecthash-proto for V2 protobuf API
https://github.com/stackb/protoreflecthash
object-hash protobuf
Last synced: 10 months ago
JSON representation
Reimplementation of https://github.com/deepmind/objecthash-proto for V2 protobuf API
- Host: GitHub
- URL: https://github.com/stackb/protoreflecthash
- Owner: stackb
- License: apache-2.0
- Created: 2023-06-19T23:06:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-06-22T20:48:51.000Z (over 2 years ago)
- Last Synced: 2025-02-14T14:51:41.643Z (11 months ago)
- Topics: object-hash, protobuf
- Language: Go
- Homepage:
- Size: 183 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/stackb/protoreflecthash/actions/workflows/ci.yaml)
protobuf
objecthash
# protoreflecthash
protoreflecthash is a re-implementation of
. That repo is now archived and
was never updated for [protobuf-apiv2](https://go.dev/blog/protobuf-apiv2).
# Usage
```
go get github.com/stackb/protoreflecthash@latest
```
```go
package main
import (
"github.com/stackb/protoreflecthash"
)
func main() {
msg := mustGetProtoMessageSomewhere()
options := []protoreflect.Option{
// protoreflect.MessageFullnameIdentifier(),
// protoreflect.FieldNamesAsKeys(),
}
hasher := protoreflect.NewHasher(options...)
hash, err := hasher.HashProto(msg.ProtoReflect())
if err != nil {
panic(err.Error())
}
fmt.Printf("%x\n", hash)
}
```
# Background
`protoreflecthash` computes the hash value for a protobuf message by taking a
sha256 of the sum the individual component hashes of the message. Special care
is taken to account for various semantics of the protobuf format.
This implementation passes all functional unit tests from the original library
[deepmind/objecthash-proto](https://github.com/deepmind/objecthash-proto)
(excluding badness detection).
Open questions remain about the handling of protobufs with extension fields and
the google.protobuf.Any type.
This package is currently experimental; hash values for messages may change
without warning until v1.