CodeSampleX

Exemplo

github.com/quic-go/qpack v0.5.1: encode and decode HTTP/3 header fields with QPACK encoder and decoder

Amostra verificada para golang github.com/quic-go/qpack v0.5.1: encode and decode HTTP/3 header fields with QPACK encoder and decoder. O contrato rodou em go…

sha256:7a051e6555d4f4bc775fdcc4292bacbb0b9caf61b239cdf56263d697dbfbcfa1

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
1
Ambiente declarado go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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-23
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-09-07

Caso

HOW
Objetivo
encode and decode HTTP/3 header fields with QPACK encoder and decoder
Pacotes
Símbolos
  • qpack.HeaderField
  • qpack.NewDecoder
  • qpack.NewEncoder
Ambiente
go 1.26.6
Criado
2026-08-23T16:55:46Z

Contrato

  1. HeaderField.IsPseudo returns true for pseudo headers starting with colon and false otherwise
  2. NewEncoder writes HeaderField sequence to bytes.Buffer and closes cleanly
  3. NewDecoder.DecodeFull decodes byte buffer back into matching HeaderField slice
  4. NewDecoder with emit callback incrementally decodes written header block

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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: encode and decode HTTP/3 header fields with QPACK encoder and decoder
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/quic-go/qpack@v0.5.1
Demonstrate these symbols/APIs:
  - qpack.HeaderField
  - qpack.NewDecoder
  - qpack.NewEncoder
Required runtime conditions:
  - ecosystem: golang
  - language: go
  - packageManager: go@1.26.6
  - runtime: go@1.26.6

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:c40b201cb9029eb3371f55918815f045490a12971534d369a9d7c321e2cec16f","contract":["HeaderField.IsPseudo returns true for pseudo headers starting with colon and false otherwise","NewEncoder writes HeaderField sequence to bytes.Buffer and closes cleanly","NewDecoder.DecodeFull decodes byte buffer back into matching HeaderField slice","NewDecoder with emit callback incrementally decodes written header block"],"goal":"encode and decode HTTP/3 header fields with QPACK encoder and decoder","kind":"HOW","packages":["pkg:golang/github.com/quic-go/qpack@v0.5.1"],"schemaVersion":1,"symbols":["qpack.HeaderField","qpack.NewDecoder","qpack.NewEncoder"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/quic-go/qpack@v0.5.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/quic-go/qpack@v0.5.1","symbols":["qpack.HeaderField","qpack.NewDecoder","qpack.NewEncoder"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require github.com/quic-go/qpack v0.5.1

require golang.org/x/net v0.28.0 // indirect
go.sum
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
main.go
package main

import (
	"bytes"
	"fmt"

	"github.com/quic-go/qpack"
)

func main() {
	headers := []qpack.HeaderField{
		{Name: ":method", Value: "GET"},
		{Name: ":path", Value: "/index.html"},
		{Name: ":scheme", Value: "https"},
		{Name: ":authority", Value: "example.com"},
		{Name: "custom-header", Value: "custom-value"},
	}

	var buf bytes.Buffer
	encoder := qpack.NewEncoder(&buf)
	for _, hf := range headers {
		if err := encoder.WriteField(hf); err != nil {
			panic(err)
		}
	}
	if err := encoder.Close(); err != nil {
		panic(err)
	}

	decoder := qpack.NewDecoder(nil)
	decoded, err := decoder.DecodeFull(buf.Bytes())
	if err != nil {
		panic(err)
	}

	for _, hf := range decoded {
		fmt.Printf("%s: %s (pseudo=%t)\n", hf.Name, hf.Value, hf.IsPseudo())
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "encode and decode HTTP/3 header fields with QPACK encoder and decoder",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/quic-go/qpack@v0.5.1"
  ],
  "symbols": [
    "qpack.HeaderField",
    "qpack.NewDecoder",
    "qpack.NewEncoder"
  ],
  "runtimeConditions": {
    "ecosystem": "golang",
    "language": "go",
    "packageManager": "go@1.26.6",
    "runtime": "go@1.26.6"
  }
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"
	"reflect"

	"github.com/quic-go/qpack"
)

func main() {
	headers := []qpack.HeaderField{
		{Name: ":method", Value: "GET"},
		{Name: ":path", Value: "/index.html"},
		{Name: ":scheme", Value: "https"},
		{Name: ":authority", Value: "example.com"},
		{Name: "custom-header", Value: "custom-value"},
	}

	if !headers[0].IsPseudo() || !headers[1].IsPseudo() || !headers[2].IsPseudo() || !headers[3].IsPseudo() {
		fmt.Fprintln(os.Stderr, "Contract failure: pseudo headers must return IsPseudo() == true")
		os.Exit(1)
	}
	if headers[4].IsPseudo() {
		fmt.Fprintln(os.Stderr, "Contract failure: normal headers must return IsPseudo() == false")
		os.Exit(1)
	}

	var buf bytes.Buffer
	encoder := qpack.NewEncoder(&buf)
	for _, hf := range headers {
		if err := encoder.WriteField(hf); err != nil {
			fmt.Fprintf(os.Stderr, "Contract failure: WriteField failed: %v\n", err)
			os.Exit(1)
		}
	}
	if err := encoder.Close(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract failure: encoder.Close failed: %v\n", err)
		os.Exit(1)
	}

	encoded := buf.Bytes()
	if len(encoded) == 0 {
		fmt.Fprintln(os.Stderr, "Contract failure: encoded bytes must not be empty")
		os.Exit(1)
	}

	decoder := qpack.NewDecoder(nil)
	decoded, err := decoder.DecodeFull(encoded)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Contract failure: DecodeFull failed: %v\n", err)
		os.Exit(1)
	}
	if !reflect.DeepEqual(headers, decoded) {
		fmt.Fprintf(os.Stderr, "Contract failure: decoded fields mismatch: got %+v, want %+v\n", decoded, headers)
		os.Exit(1)
	}

	var emitted []qpack.HeaderField
	emitDecoder := qpack.NewDecoder(func(f qpack.HeaderField) {
		emitted = append(emitted, f)
	})
	n, err := emitDecoder.Write(encoded)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Contract failure: emitDecoder.Write failed: %v\n", err)
		os.Exit(1)
	}
	if n != len(encoded) {
		fmt.Fprintf(os.Stderr, "Contract failure: emitDecoder.Write short write: got %d, want %d\n", n, len(encoded))
		os.Exit(1)
	}
	if err := emitDecoder.Close(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract failure: emitDecoder.Close failed: %v\n", err)
		os.Exit(1)
	}
	if !reflect.DeepEqual(headers, emitted) {
		fmt.Fprintf(os.Stderr, "Contract failure: emitted fields mismatch: got %+v, want %+v\n", emitted, headers)
		os.Exit(1)
	}

	fmt.Println("All contract assertions passed successfully.")
	os.Exit(0)
}

Seeder de origem

anônimo