샘플
github.com/google/uuid v1.6.0: text serialization with github.com/google/uuid MarshalText and UnmarshalText
검증된 샘플 — golang github.com/google/uuid v1.6.0: text serialization with github.com/google/uuid MarshalText and UnmarshalText. go 1.26 · linux alpine/x64 …
sha256:00a1e6998c589f038cd7634013b7c187f0d4afcdb9af4d4194ad18a26b672642
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 1
선언된 환경
windows 11 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-09-07 |
케이스
HOW- 목표
- text serialization with github.com/google/uuid MarshalText and UnmarshalText
- 심벌
-
- MarshalText
- UnmarshalText
- 생성일
- 2026-08-19T04:25:58Z
컨트랙트
- UUID.MarshalText encodes UUID into standard 36-byte UTF-8 string representation without error
- UUID.UnmarshalText decodes standard 36-byte UUID text into matching UUID value
- UUID.UnmarshalText decodes 32-character hex and URN formatted byte slices
- UUID.UnmarshalText returns error for invalid format or invalid length byte slices
- UUID.MarshalText and UnmarshalText support uuid.Nil and round trip lossless conversion
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- 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: text serialization with github.com/google/uuid MarshalText and UnmarshalText
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
- MarshalText
- UnmarshalText
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.
{"case":{"caseId":"case:sha256:1dd0a6293a3784295d77eab9a0ceb30637d8d33ffd4bcf30821b40d6fe1cbed4","contract":["UUID.MarshalText encodes UUID into standard 36-byte UTF-8 string representation without error","UUID.UnmarshalText decodes standard 36-byte UUID text into matching UUID value","UUID.UnmarshalText decodes 32-character hex and URN formatted byte slices","UUID.UnmarshalText returns error for invalid format or invalid length byte slices","UUID.MarshalText and UnmarshalText support uuid.Nil and round trip lossless conversion"],"goal":"text serialization with github.com/google/uuid MarshalText and UnmarshalText","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalText","UnmarshalText"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","ecosystem":"golang","os":"windows","osVersionBucket":"11","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["MarshalText","UnmarshalText"],"verifierAdapter":"golang@1"}
module sample
go 1.22.0
require github.com/google/uuid v1.6.0
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=
package sample
import (
"github.com/google/uuid"
)
// MarshalUUID serializes a UUID into its standard text representation.
func MarshalUUID(u uuid.UUID) ([]byte, error) {
return u.MarshalText()
}
// UnmarshalUUID deserializes text data into a UUID.
func UnmarshalUUID(data []byte) (uuid.UUID, error) {
var u uuid.UUID
err := u.UnmarshalText(data)
if err != nil {
return uuid.Nil, err
}
return u, nil
}
{
"schemaVersion": 1,
"goal": "text serialization with github.com/google/uuid MarshalText and UnmarshalText",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/uuid@v1.6.0"
],
"symbols": [
"MarshalText",
"UnmarshalText"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@11.8.0",
"runtime": "node@24.13.1"
}
}
package main
import (
"fmt"
"os"
"github.com/google/uuid"
)
func main() {
// 1. UUID.MarshalText encodes UUID into standard 36-byte UTF-8 string representation without error
original := uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
textBytes, err := original.MarshalText()
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error in MarshalText: %v\n", err)
os.Exit(1)
}
expectedStr := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
if string(textBytes) != expectedStr {
fmt.Fprintf(os.Stderr, "expected text %q, got %q\n", expectedStr, string(textBytes))
os.Exit(1)
}
if len(textBytes) != 36 {
fmt.Fprintf(os.Stderr, "expected length 36, got %d\n", len(textBytes))
os.Exit(1)
}
// 2. UUID.UnmarshalText decodes standard 36-byte UUID text into matching UUID value
var unmarshaled uuid.UUID
if err := unmarshaled.UnmarshalText(textBytes); err != nil {
fmt.Fprintf(os.Stderr, "unexpected error in UnmarshalText: %v\n", err)
os.Exit(1)
}
if unmarshaled != original {
fmt.Fprintf(os.Stderr, "expected unmarshaled UUID %v, got %v\n", original, unmarshaled)
os.Exit(1)
}
// 3. UUID.UnmarshalText decodes 32-character hex and URN formatted byte slices
hexBytes := []byte("6ba7b8109dad11d180b400c04fd430c8")
var hexUUID uuid.UUID
if err := hexUUID.UnmarshalText(hexBytes); err != nil {
fmt.Fprintf(os.Stderr, "unexpected error in UnmarshalText with hex: %v\n", err)
os.Exit(1)
}
if hexUUID != original {
fmt.Fprintf(os.Stderr, "hex decode mismatch: got %v, want %v\n", hexUUID, original)
os.Exit(1)
}
urnBytes := []byte("urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8")
var urnUUID uuid.UUID
if err := urnUUID.UnmarshalText(urnBytes); err != nil {
fmt.Fprintf(os.Stderr, "unexpected error in UnmarshalText with URN: %v\n", err)
os.Exit(1)
}
if urnUUID != original {
fmt.Fprintf(os.Stderr, "URN decode mismatch: got %v, want %v\n", urnUUID, original)
os.Exit(1)
}
// 4. UUID.UnmarshalText returns error for invalid format or invalid length byte slices
invalidInputs := [][]byte{
[]byte(""),
[]byte("not-a-uuid"),
[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430cg"), // invalid hex 'g'
[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c"), // 35 chars
[]byte("6ba7b810-9dad-11d1-80b4-00c04fd430c89"), // 37 chars
}
for _, input := range invalidInputs {
var u uuid.UUID
if err := u.UnmarshalText(input); err == nil {
fmt.Fprintf(os.Stderr, "expected error for invalid input %q, got nil\n", string(input))
os.Exit(1)
}
}
// 5. UUID.MarshalText and UnmarshalText support uuid.Nil and round trip lossless conversion
nilBytes, err := uuid.Nil.MarshalText()
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error in uuid.Nil.MarshalText: %v\n", err)
os.Exit(1)
}
if string(nilBytes) != "00000000-0000-0000-0000-000000000000" {
fmt.Fprintf(os.Stderr, "unexpected nil text: %q\n", string(nilBytes))
os.Exit(1)
}
var unmarshaledNil uuid.UUID
if err := unmarshaledNil.UnmarshalText(nilBytes); err != nil {
fmt.Fprintf(os.Stderr, "unexpected error unmarshaling nil UUID text: %v\n", err)
os.Exit(1)
}
if unmarshaledNil != uuid.Nil {
fmt.Fprintf(os.Stderr, "expected uuid.Nil, got %v\n", unmarshaledNil)
os.Exit(1)
}
// Random UUID round trip
randomUUID := uuid.New()
randomText, err := randomUUID.MarshalText()
if err != nil {
fmt.Fprintf(os.Stderr, "unexpected error marshaling random UUID: %v\n", err)
os.Exit(1)
}
var roundTripUUID uuid.UUID
if err := roundTripUUID.UnmarshalText(randomText); err != nil {
fmt.Fprintf(os.Stderr, "unexpected error unmarshaling random UUID: %v\n", err)
os.Exit(1)
}
if roundTripUUID != randomUUID {
fmt.Fprintf(os.Stderr, "round trip mismatch: got %v, want %v\n", roundTripUUID, randomUUID)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
오리진 시더
익명