Beispiel
go.opentelemetry.io/proto/otlp v1.9.0: v1.NumberDataPoint_AsInt
Verifiziertes Beispiel für golang go.opentelemetry.io/proto/otlp v1.9.0: v1.NumberDataPoint_AsInt. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker…
sha256:911f50d6409d50316e36d7bbcd5715c08aac03a8c69d95a8371cfcc3032e0d69
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 go
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-05 |
Fall
HOW- Ziel
- verify go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
- Symbole
-
- go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt
- Erstellt
- 2026-09-05T17:43:40Z
Contract
- NumberDataPoint_AsInt wraps an int64 scalar value as a NumberDataPoint oneof variant.
- NumberDataPoint.GetAsInt returns the wrapped int64 when NumberDataPoint_AsInt is set and GetAsDouble returns zero.
- NumberDataPoint with NumberDataPoint_AsInt roundtrips through protobuf binary wire format without data loss.
- NumberDataPoint with NumberDataPoint_AsInt roundtrips through protojson format preserving 64-bit integer values.
- NumberDataPoint_AsInt preserves explicit zero value distinction from unpopulated NumberDataPoint.
- proto.Clone creates an isolated deep copy of NumberDataPoint containing NumberDataPoint_AsInt.
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Quelltext
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 go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0
Demonstrate these symbols/APIs:
- go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt
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:7252137772b54b91752c47b03e4b109445c93a0e07440077aed81781d47be315","contract":["NumberDataPoint_AsInt wraps an int64 scalar value as a NumberDataPoint oneof variant.","NumberDataPoint.GetAsInt returns the wrapped int64 when NumberDataPoint_AsInt is set and GetAsDouble returns zero.","NumberDataPoint with NumberDataPoint_AsInt roundtrips through protobuf binary wire format without data loss.","NumberDataPoint with NumberDataPoint_AsInt roundtrips through protojson format preserving 64-bit integer values.","NumberDataPoint_AsInt preserves explicit zero value distinction from unpopulated NumberDataPoint.","proto.Clone creates an isolated deep copy of NumberDataPoint containing NumberDataPoint_AsInt."],"goal":"verify go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","kind":"HOW","packages":["pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"],"schemaVersion":1,"symbols":["go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt"]},"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/go.opentelemetry.io/proto/otlp@v1.9.0"],"schemaVersion":1,"subject":"pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0","symbols":["go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
go.opentelemetry.io/proto/otlp v1.9.0
google.golang.org/protobuf v1.36.11
)
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A=
go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package main
import (
"fmt"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
)
// NewIntDataPoint constructs a NumberDataPoint holding an int64 scalar metric value.
func NewIntDataPoint(val int64, timeNano uint64) *metricspb.NumberDataPoint {
return &metricspb.NumberDataPoint{
TimeUnixNano: timeNano,
Value: &metricspb.NumberDataPoint_AsInt{
AsInt: val,
},
}
}
// ExtractIntMetric retrieves the int64 metric value if the variant is NumberDataPoint_AsInt.
func ExtractIntMetric(dp *metricspb.NumberDataPoint) (int64, bool) {
if dp == nil {
return 0, false
}
if v, ok := dp.GetValue().(*metricspb.NumberDataPoint_AsInt); ok {
return v.AsInt, true
}
return 0, false
}
func main() {
dp := NewIntDataPoint(1042, 1700000000000000000)
val, ok := ExtractIntMetric(dp)
fmt.Printf("DataPoint val=%d ok=%v asInt=%d\n", val, ok, dp.GetAsInt())
}
{
"schemaVersion": 1,
"goal": "verify go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt in pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0",
"kind": "HOW",
"packages": [
"pkg:golang/go.opentelemetry.io/proto/otlp@v1.9.0"
],
"symbols": [
"go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt"
]
}
package main
import (
"bytes"
"fmt"
"math"
"os"
metricspb "go.opentelemetry.io/proto/otlp/metrics/v1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
func assert(condition bool, message string) {
if !condition {
fmt.Fprintf(os.Stderr, "assertion failed: %s\n", message)
os.Exit(1)
}
}
func main() {
// Assertion 1: NumberDataPoint_AsInt wraps an int64 scalar value as a NumberDataPoint oneof variant.
{
intVal := &metricspb.NumberDataPoint_AsInt{AsInt: 42}
dp := &metricspb.NumberDataPoint{Value: intVal}
assert(dp.GetValue() != nil, "expected non-nil Value")
extracted, ok := dp.GetValue().(*metricspb.NumberDataPoint_AsInt)
assert(ok, "expected Value to be *metricspb.NumberDataPoint_AsInt")
assert(extracted.AsInt == 42, "expected AsInt to equal 42")
}
// Assertion 2: NumberDataPoint.GetAsInt returns the wrapped int64 when NumberDataPoint_AsInt is set and GetAsDouble returns zero.
{
dp := &metricspb.NumberDataPoint{
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 1024},
}
assert(dp.GetAsInt() == 1024, "expected GetAsInt() == 1024")
assert(dp.GetAsDouble() == 0.0, "expected default GetAsDouble() == 0.0 for integer point")
}
// Assertion 3: NumberDataPoint with NumberDataPoint_AsInt roundtrips through protobuf binary wire format without data loss.
{
testValues := []int64{0, -1, 42, 1000000, math.MinInt64, math.MaxInt64}
for _, v := range testValues {
orig := &metricspb.NumberDataPoint{
TimeUnixNano: 1700000060000000000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: v},
}
wire, err := proto.Marshal(orig)
assert(err == nil, "proto.Marshal failed")
assert(len(wire) > 0, "marshaled wire length must be > 0")
var decoded metricspb.NumberDataPoint
err = proto.Unmarshal(wire, &decoded)
assert(err == nil, "proto.Unmarshal failed")
assert(proto.Equal(orig, &decoded), "proto.Equal failed for protobuf roundtrip")
assert(decoded.GetAsInt() == v, "unmarshaled GetAsInt() mismatch")
_, ok := decoded.GetValue().(*metricspb.NumberDataPoint_AsInt)
assert(ok, "decoded Value is not *metricspb.NumberDataPoint_AsInt")
}
}
// Assertion 4: NumberDataPoint with NumberDataPoint_AsInt roundtrips through protojson format preserving 64-bit integer values.
{
orig := &metricspb.NumberDataPoint{
TimeUnixNano: 1700000060000000000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 8080},
}
jsonBytes, err := protojson.Marshal(orig)
assert(err == nil, "protojson.Marshal failed")
assert(bytes.Contains(jsonBytes, []byte(`"asInt"`)), "json must contain 'asInt'")
var jsonDecoded metricspb.NumberDataPoint
err = protojson.Unmarshal(jsonBytes, &jsonDecoded)
assert(err == nil, "protojson.Unmarshal failed")
assert(proto.Equal(orig, &jsonDecoded), "proto.Equal failed for protojson roundtrip")
assert(jsonDecoded.GetAsInt() == 8080, "protojson roundtrip GetAsInt() mismatch")
}
// Assertion 5: NumberDataPoint_AsInt preserves explicit zero value distinction from unpopulated NumberDataPoint.
{
zeroPoint := &metricspb.NumberDataPoint{
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 0},
}
emptyPoint := &metricspb.NumberDataPoint{}
assert(zeroPoint.GetValue() != nil, "explicit zero point must have non-nil Value")
assert(emptyPoint.GetValue() == nil, "unpopulated point must have nil Value")
assert(zeroPoint.GetAsInt() == 0, "explicit zero point GetAsInt() must return 0")
assert(emptyPoint.GetAsInt() == 0, "unpopulated point GetAsInt() must return 0")
}
// Assertion 6: proto.Clone creates an isolated deep copy of NumberDataPoint containing NumberDataPoint_AsInt.
{
orig := &metricspb.NumberDataPoint{
TimeUnixNano: 1700000060000000000,
Value: &metricspb.NumberDataPoint_AsInt{AsInt: 50},
}
cloned := proto.Clone(orig).(*metricspb.NumberDataPoint)
assert(proto.Equal(orig, cloned), "cloned NumberDataPoint must equal original")
// Mutate cloned value
cloned.Value = &metricspb.NumberDataPoint_AsInt{AsInt: 999}
// Verify original is untouched
assert(orig.GetAsInt() == 50, "original Value was mutated after modifying clone")
assert(cloned.GetAsInt() == 999, "cloned Value was not updated")
}
fmt.Println("PASS: all go.opentelemetry.io/proto/otlp/metrics/v1.NumberDataPoint_AsInt contract assertions verified")
}
Ursprungs-Seeder
anonym