示例
google.golang.org/protobuf v1.36.4: proto.Equal
已验证示例 — golang google.golang.org/protobuf v1.36.4: proto.Equal. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: proto.Equal returns true when…
sha256:7fdc425068384ec073f76afc7fa20b2e533f16a934cd93f12195c2aeee4930bf
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-10-24 |
案例
HOW- 目标
- verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4
- 符号
-
- google.golang.org/protobuf/proto.Equal
- 创建时间
- 2026-10-24T13:31:54Z
契约
- proto.Equal returns true when comparing two untyped nil values or two typed nil pointers of the same message type
- proto.Equal returns false when comparing an untyped nil interface with a typed nil message pointer
- proto.Equal returns false when comparing messages with different descriptors even when both are empty or typed nil
- proto.Equal returns true for distinct message instances with identical scalar field values and false when scalar fields differ
- proto.Equal distinguishes unset proto2 fields from explicitly set zero-value proto2 fields
- proto.Equal treats floating-point NaN values as equal while distinguishing positive and negative zero
- proto.Equal compares map entries independent of insertion order and repeated list elements in order
- proto.Equal includes unparsed unknown wire fields in equality comparisons
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/protobuf@v1.36.4
Demonstrate these symbols/APIs:
- google.golang.org/protobuf/proto.Equal
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:4bf0d44fb9296d185fc5c12378195c502a8f14d650061b3da0def2a69df5d3a1","contract":["proto.Equal returns true when comparing two untyped nil values or two typed nil pointers of the same message type","proto.Equal returns false when comparing an untyped nil interface with a typed nil message pointer","proto.Equal returns false when comparing messages with different descriptors even when both are empty or typed nil","proto.Equal returns true for distinct message instances with identical scalar field values and false when scalar fields differ","proto.Equal distinguishes unset proto2 fields from explicitly set zero-value proto2 fields","proto.Equal treats floating-point NaN values as equal while distinguishing positive and negative zero","proto.Equal compares map entries independent of insertion order and repeated list elements in order","proto.Equal includes unparsed unknown wire fields in equality comparisons"],"goal":"verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4","kind":"HOW","packages":["pkg:golang/google.golang.org/protobuf@v1.36.4"],"schemaVersion":1,"symbols":["google.golang.org/protobuf/proto.Equal"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/protobuf@v1.36.4"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/protobuf@v1.36.4","symbols":["google.golang.org/protobuf/proto.Equal"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.21
require google.golang.org/protobuf v1.36.4
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
{
"schemaVersion": 1,
"goal": "verify google.golang.org/protobuf/proto.Equal in pkg:golang/google.golang.org/protobuf@v1.36.4",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/protobuf@v1.36.4"
],
"symbols": [
"google.golang.org/protobuf/proto.Equal"
]
}
package main
import (
"fmt"
"math"
"os"
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func assert(cond bool, msg string) {
if !cond {
fmt.Fprintln(os.Stderr, "contract failed:", msg)
os.Exit(1)
}
}
func main() {
// 1. Untyped nil and typed nil of the same message type
var untypedA, untypedB proto.Message
assert(proto.Equal(untypedA, untypedB), "two untyped nil messages must be equal")
var typedNilStrA, typedNilStrB *wrapperspb.StringValue
assert(proto.Equal(typedNilStrA, typedNilStrB), "two typed nil pointers of the same message type must be equal")
// 2. Untyped nil vs typed nil pointer
assert(!proto.Equal(untypedA, typedNilStrA), "untyped nil and typed nil message pointer must not be equal")
// 3. Different message descriptors (empty or typed nil)
var typedNilInt *wrapperspb.Int64Value
assert(!proto.Equal(typedNilStrA, typedNilInt), "typed nil pointers of different message types must not be equal")
assert(!proto.Equal(&wrapperspb.StringValue{}, &wrapperspb.Int64Value{}), "empty messages of different descriptors must not be equal")
// 4. Scalar field equality and inequality across distinct instances
s1 := wrapperspb.String("hello")
s2 := wrapperspb.String("hello")
s3 := wrapperspb.String("world")
assert(s1 != s2 && proto.Equal(s1, s2), "distinct messages with identical scalar values must be equal")
assert(!proto.Equal(s1, s3), "messages with different scalar values must not be equal")
// 5. Explicit presence (proto2): unset field vs explicitly set zero-value field
unsetProto2 := &descriptorpb.FieldDescriptorProto{}
emptyNameProto2 := &descriptorpb.FieldDescriptorProto{Name: proto.String("")}
sameEmptyNameProto2 := &descriptorpb.FieldDescriptorProto{Name: proto.String("")}
assert(!proto.Equal(unsetProto2, emptyNameProto2), "unset proto2 field must not equal explicitly set empty proto2 field")
assert(proto.Equal(emptyNameProto2, sameEmptyNameProto2), "two proto2 messages with identical explicitly set zero values must be equal")
// 6. IEEE-754 floating-point NaN and signed zeros
nanA := wrapperspb.Double(math.NaN())
nanB := wrapperspb.Double(math.NaN())
assert(proto.Equal(nanA, nanB), "proto.Equal must treat NaN float values as equal")
posZero := wrapperspb.Double(0.0)
negZero := wrapperspb.Double(math.Copysign(0.0, -1.0))
assert(!proto.Equal(posZero, negZero), "proto.Equal must distinguish +0.0 and -0.0")
// 7. Map entries (order-independent) and repeated list elements (order-sensitive)
mapA := &structpb.Struct{
Fields: map[string]*structpb.Value{
"first": structpb.NewNumberValue(1),
"second": structpb.NewStringValue("two"),
},
}
mapB := &structpb.Struct{
Fields: map[string]*structpb.Value{
"second": structpb.NewStringValue("two"),
"first": structpb.NewNumberValue(1),
},
}
mapC := &structpb.Struct{
Fields: map[string]*structpb.Value{
"first": structpb.NewNumberValue(1),
"second": structpb.NewStringValue("different"),
},
}
assert(proto.Equal(mapA, mapB), "map fields with identical key-value pairs must be equal")
assert(!proto.Equal(mapA, mapC), "map fields with differing values must not be equal")
listA := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(1),
structpb.NewNumberValue(2),
},
}
listB := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(1),
structpb.NewNumberValue(2),
},
}
listReversed := &structpb.ListValue{
Values: []*structpb.Value{
structpb.NewNumberValue(2),
structpb.NewNumberValue(1),
},
}
assert(proto.Equal(listA, listB), "repeated fields with identical elements in order must be equal")
assert(!proto.Equal(listA, listReversed), "repeated fields with elements in different order must not be equal")
// 8. Unknown wire fields included in equality comparison
var rawUnknown []byte
rawUnknown = protowire.AppendTag(rawUnknown, 999, protowire.VarintType)
rawUnknown = protowire.AppendVarint(rawUnknown, 42)
u1 := wrapperspb.String("payload")
u2 := wrapperspb.String("payload")
u1.ProtoReflect().SetUnknown(rawUnknown)
assert(!proto.Equal(u1, u2), "message with unknown fields must not equal message without unknown fields")
u2.ProtoReflect().SetUnknown(rawUnknown)
assert(proto.Equal(u1, u2), "messages with identical known and unknown fields must be equal")
}
原始种子者
匿名