CodeSampleX

Пример

google.protobuf.any_pb2 Any and Struct packing, unpacking, type URL handling, and JSON conversion

sha256:4a5fde4311f0f3db5b6c7f575b45854ac4d367acc96b895513d1c2b14e8029ae

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда python 3.12 linux 24 · glibc x64 python 3.12 python 3.12 pip

Среды запусков проверки

Окружение Контракт Этапы Запуск
python 3.12 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · python@1python:3.12-alpine@sha256:d09d15e60962…
2026-08-27

Кейс

HOW
Цель
google.protobuf.any_pb2 Any and Struct packing, unpacking, type URL handling, and JSON conversion
Пакеты
Символы
  • google.protobuf.any_pb2.Any
  • google.protobuf.any_pb2.Any.Pack
  • google.protobuf.any_pb2.Any.Unpack
  • google.protobuf.any_pb2.Any.Is
  • google.protobuf.any_pb2.Any.TypeName
  • google.protobuf.struct_pb2.Struct
  • google.protobuf.struct_pb2.Value
  • google.protobuf.struct_pb2.ListValue
  • google.protobuf.json_format.MessageToDict
  • google.protobuf.json_format.ParseDict
Окружение
python 3.12
Создан
2026-08-27T19:21:38Z

Контракт

  1. Struct.update populates scalar, boolean, null, nested dict, and list fields with automatic Value and ListValue wrapping, while assigning unsupported types raises ValueError.
  2. Struct helper methods get_or_create_struct and get_or_create_list instantiate child containers in-place and support append, extend, and index mutation.
  3. Any.Pack serializes arbitrary protobuf messages including Struct with default type.googleapis.com URL prefix or explicit custom prefix, and TypeName extracts the clean message name.
  4. Any.Is verifies descriptor matching, while Any.Unpack deserializes the payload into matching message instances and safely returns False without modifying destination on type mismatch.
  5. MessageToDict and ParseDict round-trip Struct directly as native dictionaries and Any containers with @type discriminator metadata.

Файлы

  • NOTES.md
  • PROMPT.md
  • csx.json
  • requirements.lock
  • requirements.txt
  • spec.json
  • test/contract.py

Скачать артефакт с исходным кодом (tar.gz)

Исходный сидер

аноним