Skip to content

Commit 6136bf2

Browse files
committed
create hash version from string
Signed-off-by: radoslaw.chrzanowski <[email protected]>
1 parent 608c21c commit 6136bf2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cache/src/main/java/io/envoyproxy/controlplane/cache/VersionedResource.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.google.common.hash.Hashing;
55
import com.google.protobuf.Message;
66

7+
import java.nio.charset.StandardCharsets;
8+
79
@AutoValue
810
public abstract class VersionedResource<T extends Message> {
911

@@ -32,11 +34,15 @@ public static <T extends Message> VersionedResource<T> create(T resource) {
3234
resource,
3335
// todo: is this a stable hash?
3436
Hashing.sha256()
35-
.hashBytes(resource.toByteArray())
37+
.hashString(resourceHashCode(resource), StandardCharsets.UTF_8)
3638
.toString()
3739
);
3840
}
3941

42+
private static <T extends Message> String resourceHashCode(T resource) {
43+
return resource.getClass() + "@" + resource.hashCode();
44+
}
45+
4046
/**
4147
* Returns the resource.
4248
*/

0 commit comments

Comments
 (0)