From 1aae51579be656c7968a36136f20338698bb425e Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Sun, 1 Oct 2023 17:34:07 -0700 Subject: [PATCH] Add brief documentation for the MapField type Signed-off-by: Nic Cope --- lib/proto/proto.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/proto/proto.go b/lib/proto/proto.go index 5d33db8d..b5b7bac8 100644 --- a/lib/proto/proto.go +++ b/lib/proto/proto.go @@ -61,6 +61,15 @@ // msg.uints32s = [1, 2, 3] // print(type(msg.uints32s)) # "proto.repeated" // +// The value of a map field of a message is represented by the dict-like data +// type, MapField. Its items can be set and access in the usual ways. As with +// assignments to message fields, and assignment to a MapField performs a +// dynamic check to ensure the key and value are of the correct type. +// +// msg.string_map = {"a": "A", "b", "B"} +// msg.string_map["c"] = "C" +// print(type(msg.string_map)) # "proto.map" +// // To construct a Message from encoded binary or text data, call // Unmarshal or UnmarshalText. These two functions are exposed to // Starlark programs as proto.unmarshal{,_text}.