CodeSampleX

サンプル

github.com/google/uuid v1.6.0: MarshalBinary, UnmarshalBinary

検証済みサンプル — golang github.com/google/uuid v1.6.0: MarshalBinary, UnmarshalBinary. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:e1363fc973565db6033a4a327185b1f028680fd904648425c72e6f18efe71d96

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
2
宣言された環境 go 1.26 windows 11 x64 go 1.26 go go 1

検証実行環境

環境 コントラクト ステージ 実行日
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-19
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-09-07

ケース

HOW
ゴール
verify pkg:golang/github.com/google/uuid@v1.6.0
パッケージ
シンボル
  • github.com/google/uuid.MarshalBinary
  • github.com/google/uuid.UnmarshalBinary
環境
go 1.26.5
作成日
2026-08-18T22:44:28Z

コントラクト

  1. uuid.MarshalBinary encodes UUID into 16-byte raw slice without error
  2. uuid.MarshalBinary encodes uuid.Nil into 16 zero bytes
  3. uuid.UnmarshalBinary decodes 16-byte binary data into UUID
  4. uuid.UnmarshalBinary decodes 16 zero bytes into uuid.Nil
  5. uuid.UnmarshalBinary rejects byte slices with length other than 16 with error
  6. uuid.MarshalBinary and uuid.UnmarshalBinary round-trip accurately preserves UUID value

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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/google/uuid@v1.6.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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.
csx.json
{"case":{"caseId":"case:sha256:44ae1af78b91eecac1ce4b3e41df1aab87c014a6067aa09d2cb01c7b2227e3c8","contract":["uuid.MarshalBinary encodes UUID into 16-byte raw slice without error","uuid.MarshalBinary encodes uuid.Nil into 16 zero bytes","uuid.UnmarshalBinary decodes 16-byte binary data into UUID","uuid.UnmarshalBinary decodes 16 zero bytes into uuid.Nil","uuid.UnmarshalBinary rejects byte slices with length other than 16 with error","uuid.MarshalBinary and uuid.UnmarshalBinary round-trip accurately preserves UUID value"],"goal":"verify pkg:golang/github.com/google/uuid@v1.6.0","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["github.com/google/uuid.MarshalBinary","github.com/google/uuid.UnmarshalBinary"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","language":"go","os":"windows","osVersionBucket":"11","packageManager":"go","packageManagerVersion":"1.26.5","runtime":"go","runtimeVersion":"1.26.5","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["github.com/google/uuid.MarshalBinary","github.com/google/uuid.UnmarshalBinary"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22.0

require github.com/google/uuid v1.6.0
go.sum
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
main.go
package main

import (
	"fmt"
	"log"

	"github.com/google/uuid"
)

// MarshalUUIDBinary converts a UUID to its binary representation (16 bytes).
func MarshalUUIDBinary(u uuid.UUID) ([]byte, error) {
	return u.MarshalBinary()
}

// UnmarshalUUIDBinary decodes binary data into a UUID.
func UnmarshalUUIDBinary(data []byte) (uuid.UUID, error) {
	var u uuid.UUID
	err := u.UnmarshalBinary(data)
	return u, err
}

func main() {
	original := uuid.New()
	bin, err := MarshalUUIDBinary(original)
	if err != nil {
		log.Fatalf("MarshalBinary failed: %v", err)
	}
	fmt.Printf("Marshaled binary (%d bytes): %x\n", len(bin), bin)

	restored, err := UnmarshalUUIDBinary(bin)
	if err != nil {
		log.Fatalf("UnmarshalBinary failed: %v", err)
	}
	fmt.Printf("Restored UUID: %s (matches: %t)\n", restored.String(), restored == original)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/google/uuid@v1.6.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// Assertion 1: uuid.MarshalBinary encodes UUID into 16-byte raw slice without error
	sampleUUID, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: setup parse failed: %v\n", err)
		os.Exit(1)
	}

	marshaled, err := sampleUUID.MarshalBinary()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalBinary failed: %v\n", err)
		os.Exit(1)
	}
	if len(marshaled) != 16 {
		fmt.Fprintf(os.Stderr, "FAIL: expected byte length 16, got %d\n", len(marshaled))
		os.Exit(1)
	}
	if !bytes.Equal(marshaled, sampleUUID[:]) {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalBinary output did not match underlying slice: got %x, want %x\n", marshaled, sampleUUID[:])
		os.Exit(1)
	}

	// Assertion 2: uuid.MarshalBinary encodes uuid.Nil into 16 zero bytes
	nilMarshaled, err := uuid.Nil.MarshalBinary()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalBinary on Nil failed: %v\n", err)
		os.Exit(1)
	}
	if len(nilMarshaled) != 16 {
		fmt.Fprintf(os.Stderr, "FAIL: expected 16 zero bytes, got %d bytes\n", len(nilMarshaled))
		os.Exit(1)
	}
	for i, b := range nilMarshaled {
		if b != 0 {
			fmt.Fprintf(os.Stderr, "FAIL: non-zero byte at index %d: %x\n", i, b)
			os.Exit(1)
		}
	}

	// Assertion 3: uuid.UnmarshalBinary decodes 16-byte binary data into UUID
	var u1 uuid.UUID
	rawBytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
	if err := u1.UnmarshalBinary(rawBytes); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalBinary failed on valid 16-byte slice: %v\n", err)
		os.Exit(1)
	}
	if u1 != sampleUUID {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalBinary mismatch: got %s, want %s\n", u1, sampleUUID)
		os.Exit(1)
	}

	// Assertion 4: uuid.UnmarshalBinary decodes 16 zero bytes into uuid.Nil
	var uNil uuid.UUID
	zeroBytes := make([]byte, 16)
	if err := uNil.UnmarshalBinary(zeroBytes); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalBinary failed on zero bytes: %v\n", err)
		os.Exit(1)
	}
	if uNil != uuid.Nil {
		fmt.Fprintf(os.Stderr, "FAIL: expected uuid.Nil, got %s\n", uNil)
		os.Exit(1)
	}

	// Assertion 5: uuid.UnmarshalBinary rejects byte slices with length other than 16 with error
	invalidLengths := [][]byte{
		{},
		{0x01, 0x02, 0x03},
		make([]byte, 15),
		make([]byte, 17),
		make([]byte, 36),
	}
	for _, inv := range invalidLengths {
		var uInv uuid.UUID
		if err := uInv.UnmarshalBinary(inv); err == nil {
			fmt.Fprintf(os.Stderr, "FAIL: expected error for slice of length %d, got nil\n", len(inv))
			os.Exit(1)
		}
	}

	// Assertion 6: uuid.MarshalBinary and uuid.UnmarshalBinary round-trip accurately preserves UUID value
	randUUID := uuid.New()
	encoded, err := randUUID.MarshalBinary()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: MarshalBinary on random UUID failed: %v\n", err)
		os.Exit(1)
	}
	var decoded uuid.UUID
	if err := decoded.UnmarshalBinary(encoded); err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: UnmarshalBinary round-trip failed: %v\n", err)
		os.Exit(1)
	}
	if decoded != randUUID {
		fmt.Fprintf(os.Stderr, "FAIL: round-trip value mismatch: got %s, want %s\n", decoded, randUUID)
		os.Exit(1)
	}

	fmt.Println("PASS: all contract assertions passed for uuid.MarshalBinary and uuid.UnmarshalBinary")
}

オリジンシーダー

匿名