샘플
github.com/gogo/protobuf v1.3.2: proto.Marshal, proto.Unmarshal
검증된 샘플 — golang github.com/gogo/protobuf v1.3.2: proto.Marshal, proto.Unmarshal. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:4d185356ebadfea42406fc270e2dc068c70dc81b1854ff2aca61cddaac39d000
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-28 |
케이스
HOW- 목표
- verify pkg:golang/github.com/gogo/protobuf@v1.3.2
- 심벌
-
- proto.Marshal
- proto.Unmarshal
- 환경
- go 1.26.6
- 생성일
- 2026-08-28T00:46:12Z
컨트랙트
- proto.Marshal encodes a proto.Message into wire format bytes
- proto.Unmarshal decodes wire format bytes into a proto.Message
- proto.Unmarshal returns an error when decoding invalid or corrupted wire format bytes
파일
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
소스
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 pkg:golang/github.com/gogo/protobuf@v1.3.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/gogo/protobuf@v1.3.2
Demonstrate these symbols/APIs:
- proto.Marshal
- proto.Unmarshal
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.
package sample
import (
"testing"
"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"
)
func TestContractMarshalUnmarshal(t *testing.T) {
// 1. Verify proto.Marshal and proto.Unmarshal on string value
testStr := "test-protobuf-payload"
data, err := MarshalStringValue(testStr)
if err != nil {
t.Fatalf("MarshalStringValue failed: %v", err)
}
if len(data) == 0 {
t.Fatalf("expected non-empty byte slice from MarshalStringValue")
}
decodedStr, err := UnmarshalStringValue(data)
if err != nil {
t.Fatalf("UnmarshalStringValue failed: %v", err)
}
if decodedStr != testStr {
t.Fatalf("expected %q, got %q", testStr, decodedStr)
}
// 2. Verify proto.Marshal and proto.Unmarshal on int64 value
var testInt int64 = 987654321
intData, err := MarshalInt64Value(testInt)
if err != nil {
t.Fatalf("MarshalInt64Value failed: %v", err)
}
if len(intData) == 0 {
t.Fatalf("expected non-empty byte slice from MarshalInt64Value")
}
decodedInt, err := UnmarshalInt64Value(intData)
if err != nil {
t.Fatalf("UnmarshalInt64Value failed: %v", err)
}
if decodedInt != testInt {
t.Fatalf("expected %d, got %d", testInt, decodedInt)
}
// 3. Verify proto.Unmarshal returns error on invalid/corrupted wire format
corruptedData := []byte{0xff, 0xff, 0xff}
target := &types.StringValue{}
if err := proto.Unmarshal(corruptedData, target); err == nil {
t.Fatalf("expected error when unmarshaling corrupted protobuf data, got nil")
}
}
{"case":{"caseId":"case:sha256:d94c8684885798f5fbe292f50279894d24bac46c30fd84d2c94402f37cc9496f","contract":["proto.Marshal encodes a proto.Message into wire format bytes","proto.Unmarshal decodes wire format bytes into a proto.Message","proto.Unmarshal returns an error when decoding invalid or corrupted wire format bytes"],"goal":"verify pkg:golang/github.com/gogo/protobuf@v1.3.2","kind":"HOW","packages":["pkg:golang/github.com/gogo/protobuf@v1.3.2"],"schemaVersion":1,"symbols":["proto.Marshal","proto.Unmarshal"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/gogo/protobuf@v1.3.2"],"schemaVersion":1,"subject":"pkg:golang/github.com/gogo/protobuf@v1.3.2","symbols":["proto.Marshal","proto.Unmarshal"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require github.com/gogo/protobuf v1.3.2
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
package sample
import (
"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"
)
// MarshalStringValue encodes a StringValue protobuf message into binary wire format.
func MarshalStringValue(val string) ([]byte, error) {
msg := &types.StringValue{Value: val}
return proto.Marshal(msg)
}
// UnmarshalStringValue decodes binary wire format data into a StringValue protobuf message.
func UnmarshalStringValue(data []byte) (string, error) {
msg := &types.StringValue{}
if err := proto.Unmarshal(data, msg); err != nil {
return "", err
}
return msg.GetValue(), nil
}
// MarshalInt64Value encodes an Int64Value protobuf message into binary wire format.
func MarshalInt64Value(val int64) ([]byte, error) {
msg := &types.Int64Value{Value: val}
return proto.Marshal(msg)
}
// UnmarshalInt64Value decodes binary wire format data into an Int64Value protobuf message.
func UnmarshalInt64Value(data []byte) (int64, error) {
msg := &types.Int64Value{}
if err := proto.Unmarshal(data, msg); err != nil {
return 0, err
}
return msg.GetValue(), nil
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/gogo/protobuf@v1.3.2",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/gogo/protobuf@v1.3.2"
],
"symbols": [
"proto.Marshal",
"proto.Unmarshal"
]
}
오리진 시더
익명