CodeSampleX

サンプル

Convert between dynamic Go data structures and Protocol Buffers Struct, ListValue, and Value with structpb

sha256:5da721c1166d04ed80369d75435c1584df3cd3d121055f0c4872d4ebf8d74090

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

実行証拠

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

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 go linux 24 · ubuntu · glibc 2.39 x64 go go 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
ゴール
Convert between dynamic Go data structures and Protocol Buffers Struct, ListValue, and Value with structpb
パッケージ
シンボル
  • google.golang.org/protobuf/types/known/structpb.ListValue.AsSlice
  • google.golang.org/protobuf/types/known/structpb.NewList
  • google.golang.org/protobuf/types/known/structpb.NewStruct
  • google.golang.org/protobuf/types/known/structpb.NewValue
  • google.golang.org/protobuf/types/known/structpb.Struct.AsMap
  • google.golang.org/protobuf/types/known/structpb.Value.AsInterface
環境
go
作成日
2026-08-28T09:04:35Z

コントラクト

  1. structpb.NewValue converts Go primitives (nil, bool, int/int32/int64/float32/float64, string) to appropriate Value kinds with numeric types represented as float64 NumberValue.
  2. structpb.NewStruct converts Go maps into *structpb.Struct, and Struct.AsMap converts it back to map[string]interface{}, while calling AsMap on a nil receiver safely returns an empty non-nil map.
  3. structpb.NewList converts Go slices into *structpb.ListValue, and ListValue.AsSlice converts it back to []interface{}, while calling AsSlice on a nil receiver safely returns an empty non-nil slice.
  4. structpb.Value.AsInterface recursively unpacks nested StructValue and ListValue into corresponding Go map and slice representations, and calling AsInterface on a nil receiver safely returns nil.
  5. structpb.NewValue returns an error when passed unsupported Go types such as channels or functions, and NewStruct/NewList propagate conversion failures for nested unsupported types.
  6. structpb.Struct supports proto binary wire serialization and protojson serialization formatting as a standard JSON object.

ファイル

  • NOTES.md
  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • structpb_test.go

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

オリジンシーダー

匿名