CodeSampleX

サンプル

google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d: httpbody.HttpBody

検証済みサンプル — golang google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d: httpbody.HttpBody. go 1.26 · linux alpine/x64 · docker で…

sha256:78c89b104adb271bce262e442609e9a8f173de6b4ee4f9d53cb3a4a69c9c02c9

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 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 google.golang.org/genproto/googleapis/api/httpbody.HttpBody in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d
パッケージ
シンボル
  • google.golang.org/genproto/googleapis/api/httpbody.HttpBody
作成日
2026-08-28T10:17:38Z

コントラクト

  1. httpbody.HttpBody encapsulates raw payload bytes with HTTP content-type header string
  2. httpbody.HttpBody serializes and deserializes accurately with protobuf wire format
  3. httpbody.HttpBody stores arbitrary application metadata extensions as protobuf Any messages
  4. httpbody.HttpBody provides safe getters with default values for empty and nil instances

ファイル

  • 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 google.golang.org/genproto/googleapis/api/httpbody.HttpBody in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d
Demonstrate these symbols/APIs:
  - google.golang.org/genproto/googleapis/api/httpbody.HttpBody

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:73e31a04656fa30ab22ee59fa0149a0d09bfa2b46cccf834ed85f470e0a2b5a6","contract":["httpbody.HttpBody encapsulates raw payload bytes with HTTP content-type header string","httpbody.HttpBody serializes and deserializes accurately with protobuf wire format","httpbody.HttpBody stores arbitrary application metadata extensions as protobuf Any messages","httpbody.HttpBody provides safe getters with default values for empty and nil instances"],"goal":"verify google.golang.org/genproto/googleapis/api/httpbody.HttpBody in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d","kind":"HOW","packages":["pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d"],"schemaVersion":1,"symbols":["google.golang.org/genproto/googleapis/api/httpbody.HttpBody"]},"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/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d","symbols":["google.golang.org/genproto/googleapis/api/httpbody.HttpBody"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.25.0

require (
	google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d
	google.golang.org/protobuf v1.36.11
)
go.sum
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d h1:/aDRtSZJjyLQzm75d+a1wOJaqyKBMvIAfeQmoa3ORiI=
google.golang.org/genproto/googleapis/api v0.0.0-20260406210006-6f92a3bedf2d/go.mod h1:etfGUgejTiadZAUaEP14NP97xi1RGeawqkjDARA/UOs=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
main.go
package main

import (
	"bytes"
	"fmt"
	"log"

	"google.golang.org/genproto/googleapis/api/httpbody"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
)

func main() {
	// Create an HttpBody representing an HTTP payload with metadata
	metaBody := &httpbody.HttpBody{
		ContentType: "text/plain",
		Data:        []byte("metadata payload"),
	}
	metaAny, err := anypb.New(metaBody)
	if err != nil {
		log.Fatalf("failed to create anypb extension: %v", err)
	}

	body := &httpbody.HttpBody{
		ContentType: "application/json",
		Data:        []byte(`{"status":"success","items":[1,2,3]}`),
		Extensions:  []*anypb.Any{metaAny},
	}

	data, err := proto.Marshal(body)
	if err != nil {
		log.Fatalf("failed to marshal HttpBody: %v", err)
	}

	var decoded httpbody.HttpBody
	if err := proto.Unmarshal(data, &decoded); err != nil {
		log.Fatalf("failed to unmarshal HttpBody: %v", err)
	}

	fmt.Printf("Content-Type: %s\n", decoded.GetContentType())
	fmt.Printf("Data: %s\n", string(decoded.GetData()))
	fmt.Printf("Extensions count: %d\n", len(decoded.GetExtensions()))
	if !bytes.Equal(decoded.GetData(), body.GetData()) {
		log.Fatalf("decoded data mismatch")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/genproto/googleapis/api/httpbody.HttpBody in pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/genproto/googleapis/api@v0.0.0-20260406210006-6f92a3bedf2d"
  ],
  "symbols": [
    "google.golang.org/genproto/googleapis/api/httpbody.HttpBody"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

	"google.golang.org/genproto/googleapis/api/httpbody"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/types/known/anypb"
)

func assert(condition bool, message string) {
	if !condition {
		fmt.Fprintf(os.Stderr, "Assertion failed: %s\n", message)
		os.Exit(1)
	}
}

func main() {
	// 1. httpbody.HttpBody encapsulates raw payload bytes with HTTP content-type header string
	payload := []byte(`{"name":"test-resource","count":42}`)
	body := &httpbody.HttpBody{
		ContentType: "application/json",
		Data:        payload,
	}
	assert(body.GetContentType() == "application/json", "ContentType must match initial value")
	assert(bytes.Equal(body.GetData(), payload), "Data must match payload bytes")
	assert(len(body.GetExtensions()) == 0, "Extensions must be empty by default")

	// 2. httpbody.HttpBody serializes and deserializes accurately with protobuf wire format
	wireData, err := proto.Marshal(body)
	assert(err == nil, "proto.Marshal(body) must succeed")
	assert(len(wireData) > 0, "marshaled bytes must not be empty")

	var decoded httpbody.HttpBody
	err = proto.Unmarshal(wireData, &decoded)
	assert(err == nil, "proto.Unmarshal(wireData) must succeed")
	assert(decoded.GetContentType() == body.GetContentType(), "decoded ContentType must match")
	assert(bytes.Equal(decoded.GetData(), body.GetData()), "decoded Data must match original bytes")
	assert(len(decoded.GetExtensions()) == 0, "decoded Extensions must remain empty")

	// 3. httpbody.HttpBody stores arbitrary application metadata extensions as protobuf Any messages
	nested := &httpbody.HttpBody{
		ContentType: "text/plain",
		Data:        []byte("extension-data"),
	}
	extAny, err := anypb.New(nested)
	assert(err == nil, "anypb.New(nested) must succeed")

	bodyWithExt := &httpbody.HttpBody{
		ContentType: "application/octet-stream",
		Data:        []byte{0xDE, 0xAD, 0xBE, 0xEF},
		Extensions:  []*anypb.Any{extAny},
	}
	assert(len(bodyWithExt.GetExtensions()) == 1, "Extensions length must be 1")

	extWire, err := proto.Marshal(bodyWithExt)
	assert(err == nil, "proto.Marshal(bodyWithExt) must succeed")

	var decodedWithExt httpbody.HttpBody
	err = proto.Unmarshal(extWire, &decodedWithExt)
	assert(err == nil, "proto.Unmarshal(extWire) must succeed")
	assert(len(decodedWithExt.GetExtensions()) == 1, "decoded Extensions length must be 1")

	var unmarshaledExt httpbody.HttpBody
	err = anypb.UnmarshalTo(decodedWithExt.GetExtensions()[0], &unmarshaledExt, proto.UnmarshalOptions{})
	assert(err == nil, "anypb.UnmarshalTo must succeed for decoded extension")
	assert(unmarshaledExt.GetContentType() == "text/plain", "unmarshaled extension ContentType must match")
	assert(bytes.Equal(unmarshaledExt.GetData(), []byte("extension-data")), "unmarshaled extension Data must match")

	// 4. httpbody.HttpBody provides safe getters with default values for empty and nil instances
	emptyBody := &httpbody.HttpBody{}
	assert(emptyBody.GetContentType() == "", "emptyBody.GetContentType() must return empty string")
	assert(emptyBody.GetData() == nil, "emptyBody.GetData() must return nil")
	assert(emptyBody.GetExtensions() == nil, "emptyBody.GetExtensions() must return nil")

	var nilBody *httpbody.HttpBody
	assert(nilBody.GetContentType() == "", "nilBody.GetContentType() must return empty string")
	assert(nilBody.GetData() == nil, "nilBody.GetData() must return nil")
	assert(nilBody.GetExtensions() == nil, "nilBody.GetExtensions() must return nil")

	fmt.Println("All contract assertions for httpbody.HttpBody passed successfully.")
}

オリジンシーダー

匿名