var Module = &starlarkstruct.Module{ Name: "proto", Members: starlark.StringDict{ "file": starlark.NewBuiltin("proto.file", file), "has": starlark.NewBuiltin("proto.has", has), "marshal": starlark.NewBuiltin("proto.marshal", marshal), "marshal_text": starlark.NewBuiltin("proto.marshal_text", marshal), "set_field": starlark.NewBuiltin("proto.set_field", setFieldStarlark), "get_field": starlark.NewBuiltin("proto.get_field", getFieldStarlark), "unmarshal": starlark.NewBuiltin("proto.unmarshal", unmarshal), "unmarshal_text": starlark.NewBuiltin("proto.unmarshal_text", unmarshal_text), }, }
func SetPool(thread *starlark.Thread, pool DescriptorPool)
SetPool associates with the specified Starlark thread the descriptor pool used to find descriptors for .proto files and to instantiate messages from descriptors. Clients must call SetPool for a Starlark thread to use this package.
For example:
SetPool(thread, protoregistry.GlobalFiles)
A DescriptorPool loads FileDescriptors by path name or package name, possibly on demand.
It is a superinterface of protodesc.Resolver, so any Resolver implementation is a valid pool. For example. protoregistry.GlobalFiles, which loads FileDescriptors from the compressed binary information in all the *.pb.go files linked into the process; and protodesc.NewFiles, which holds a set of FileDescriptorSet messages. See star2proto for example usage.
type DescriptorPool interface { FindFileByPath(string) (protoreflect.FileDescriptor, error) }
func Pool(thread *starlark.Thread) DescriptorPool
Pool returns the descriptor pool previously associated with this thread.
An EnumDescriptor is an immutable Starlark value that describes an protocol enum type.
An EnumDescriptor contains a reference to a protoreflect.EnumDescriptor. Two EnumDescriptor values compare equal if and only if they refer to the same protoreflect.EnumDescriptor.
An EnumDescriptor may be called like a function. It converts its sole argument, which must be an int, string, or EnumValueDescriptor, to an EnumValueDescriptor.
The fields of an EnumDescriptor value are the values of the enumeration, each of type EnumValueDescriptor.
type EnumDescriptor struct { Desc protoreflect.EnumDescriptor }
func (e EnumDescriptor) Attr(name string) (starlark.Value, error)
func (e EnumDescriptor) AttrNames() []string
func (e EnumDescriptor) CallInternal(_ *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
The Call method implements the starlark.Callable interface. A call to an enum descriptor converts its argument to a value of that enum type.
func (e EnumDescriptor) Freeze()
func (e EnumDescriptor) Hash() (h uint32, err error)
func (e EnumDescriptor) Name() string
func (e EnumDescriptor) String() string
func (e EnumDescriptor) Truth() starlark.Bool
func (e EnumDescriptor) Type() string
An EnumValueDescriptor is an immutable Starlark value that represents one value of an enumeration.
An EnumValueDescriptor contains a reference to a protoreflect.EnumValueDescriptor. Two EnumValueDescriptor values compare equal if and only if they refer to the same protoreflect.EnumValueDescriptor.
An EnumValueDescriptor has the following fields:
index -- int, index of this value within the enum sequence name -- string, name of this enum value number -- int, numeric value of this enum value type -- EnumDescriptor, the enum type to which this value belongs
type EnumValueDescriptor struct { Desc protoreflect.EnumValueDescriptor }
func (e EnumValueDescriptor) Attr(name string) (starlark.Value, error)
func (e EnumValueDescriptor) AttrNames() []string
func (x EnumValueDescriptor) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)
func (e EnumValueDescriptor) Freeze()
func (e EnumValueDescriptor) Hash() (h uint32, err error)
func (e EnumValueDescriptor) String() string
func (e EnumValueDescriptor) Truth() starlark.Bool
func (e EnumValueDescriptor) Type() string
A FieldDescriptor is an immutable Starlark value that describes a field (possibly an extension field) of protocol message.
A FieldDescriptor value contains a reference to a protoreflect.FieldDescriptor. Two FieldDescriptor values compare equal if and only if they refer to the same protoreflect.FieldDescriptor.
The primary use for FieldDescriptors is to access extension fields of a message.
A FieldDescriptor value has not attributes. TODO(adonovan): expose metadata fields (e.g. name, type).
type FieldDescriptor struct { Desc protoreflect.FieldDescriptor }
func (d FieldDescriptor) Attr(name string) (starlark.Value, error)
func (d FieldDescriptor) AttrNames() []string
func (d FieldDescriptor) Freeze()
func (d FieldDescriptor) Hash() (h uint32, err error)
func (d FieldDescriptor) String() string
func (d FieldDescriptor) Truth() starlark.Bool
func (d FieldDescriptor) Type() string
A FileDescriptor is an immutable Starlark value that describes a .proto file. It is a reference to a protoreflect.FileDescriptor. Two FileDescriptor values compare equal if and only if they refer to the same protoreflect.FileDescriptor.
Its fields are the names of the message types (MessageDescriptor) and enum types (EnumDescriptor).
type FileDescriptor struct { Desc protoreflect.FileDescriptor // TODO(adonovan): hide field, expose method? }
func (f FileDescriptor) Attr(name string) (starlark.Value, error)
func (f FileDescriptor) AttrNames() []string
func (f FileDescriptor) Freeze()
func (f FileDescriptor) Hash() (h uint32, err error)
func (f FileDescriptor) String() string
func (f FileDescriptor) Truth() starlark.Bool
func (f FileDescriptor) Type() string
A Message is a Starlark value that wraps a protocol message.
Two Messages are equivalent if and only if they are identical.
When a Message value becomes frozen, a Starlark program may not modify the underlying protocol message, nor any Message or RepeatedField wrapper values derived from it.
type Message struct {
// contains filtered or unexported fields
}
func Unmarshal(desc protoreflect.MessageDescriptor, data []byte) (*Message, error)
Unmarshal parses the data as a binary protocol message of the specified type, and returns it as a new Starlark message value.
func UnmarshalText(desc protoreflect.MessageDescriptor, data []byte) (*Message, error)
UnmarshalText parses the data as a text protocol message of the specified type, and returns it as a new Starlark message value.
func (m *Message) Attr(name string) (starlark.Value, error)
Attr returns the value of this message's field of the specified name. Extension fields are not accessible this way as their names are not unique.
func (m *Message) AttrNames() []string
AttrNames returns the set of field names defined for this message. It satisfies the starlark.HasAttrs interface.
func (m *Message) Freeze()
func (m *Message) Hash() (h uint32, err error)
func (m *Message) Message() protoreflect.ProtoMessage
Message returns the wrapped message.
func (m *Message) SetField(name string, v starlark.Value) error
SetField updates a non-extension field of this message. It implements the HasSetField interface.
func (m *Message) String() string
func (m *Message) Truth() starlark.Bool
func (m *Message) Type() string
A MessageDescriptor is an immutable Starlark value that describes a protocol message type.
A MessageDescriptor value contains a reference to a protoreflect.MessageDescriptor. Two MessageDescriptor values compare equal if and only if they refer to the same protoreflect.MessageDescriptor.
The fields of a MessageDescriptor value are the names of any message types (MessageDescriptor), fields or extension fields (FieldDescriptor), and enum types (EnumDescriptor) nested within the declaration of this message type.
type MessageDescriptor struct { Desc protoreflect.MessageDescriptor }
func (d MessageDescriptor) Attr(name string) (starlark.Value, error)
func (d MessageDescriptor) AttrNames() []string
func (d MessageDescriptor) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)
The Call method implements the starlark.Callable interface. When a message descriptor is called, it returns a new instance of the protocol message it describes.
Message(msg) -- return a shallow copy of an existing message Message(k=v, ...) -- return a new message with the specified fields Message(dict(...)) -- return a new message with the specified fields
func (d MessageDescriptor) Freeze()
func (d MessageDescriptor) Hash() (h uint32, err error)
func (d MessageDescriptor) Name() string
func (d MessageDescriptor) String() string
func (d MessageDescriptor) Truth() starlark.Bool
func (d MessageDescriptor) Type() string
A RepeatedField is a Starlark value that wraps a repeated field of a protocol message.
An assignment to an element of a repeated field incurs a dynamic check that the new value has (or can be converted to) the correct type using conversions similar to those done when calling a MessageDescriptor to construct a message.
TODO(adonovan): make RepeatedField implement starlark.Comparable. Should the comparison include type, or be defined on the elements alone?
type RepeatedField struct {
// contains filtered or unexported fields
}
func (rf *RepeatedField) Freeze()
func (rf *RepeatedField) Hash() (uint32, error)
func (rf *RepeatedField) Index(i int) starlark.Value
func (rf *RepeatedField) Iterate() starlark.Iterator
func (rf *RepeatedField) Len() int
func (rf *RepeatedField) SetIndex(i int, v starlark.Value) error
func (rf *RepeatedField) String() string
func (rf *RepeatedField) Truth() starlark.Bool
func (rf *RepeatedField) Type() string
Name | Synopsis |
---|---|
.. | |
cmd | |
star2proto | The star2proto command executes a Starlark file and prints a protocol message, which it expects to find in a module-level variable named 'result'. |