starlarkproto

package module
v0.0.0-...-843c31c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: BSD-3-Clause Imports: 16 Imported by: 1

README

starlarkproto

GoDev

Supports protobuffers in starlark with rich type conversion to and from starlark. Most methods on lists and maps are supported, see package internals for details.

test = proto.file("github.com/emcfarlane/starlarkproto/testpb/star.proto")
m = test.Message(body="Hello, world!")
print(m)  # Message(body = Hello, world!, type = UNKNOWN, ...)
m.type = "GREETING"  # Enums can be assigned by String, Int or proto.Enum
print(m)  # Message(body = Hello, world!, type = GREETING, ...)

greeting = test.Message.Type.GREETING
print(greeting)  # GREETING

data = proto.marshal(m)  # Byte encoded string
m2 = test.Message()
proto.unmarshal(data, m2)  # Unmarshal back to message

Documentation

Overview

Package starlarkproto provides support for protocol buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModule

func NewModule(resolver protodesc.Resolver) *starlarkstruct.Module

NewModule returns a new proto module.

Types

type Descriptor

type Descriptor struct {
	// contains filtered or unexported fields
}

func NewDescriptor

func NewDescriptor(desc protoreflect.Descriptor) *Descriptor

NewDescriptor creates a new descriptor.

func (*Descriptor) Attr

func (d *Descriptor) Attr(name string) (starlark.Value, error)

func (*Descriptor) AttrNames

func (d *Descriptor) AttrNames() []string

func (*Descriptor) CallInternal

func (d *Descriptor) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

CallInternal creates a new message or enum from a descriptor.

func (*Descriptor) Descriptor

func (d *Descriptor) Descriptor() protoreflect.Descriptor

Descriptor exports proto.Descriptor

func (*Descriptor) Freeze

func (d *Descriptor) Freeze()

func (*Descriptor) Hash

func (d *Descriptor) Hash() (uint32, error)

func (*Descriptor) Name

func (d *Descriptor) Name() string

func (*Descriptor) String

func (d *Descriptor) String() string

func (*Descriptor) Truth

func (d *Descriptor) Truth() starlark.Bool

func (*Descriptor) Type

func (d *Descriptor) Type() string

type Enum

type Enum struct {
	// contains filtered or unexported fields
}

Enum is the type of a protobuf enum.

func (Enum) CompareSameType

func (x Enum) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (Enum) Freeze

func (e Enum) Freeze()

func (Enum) Hash

func (e Enum) Hash() (uint32, error)

func (Enum) String

func (e Enum) String() string

func (Enum) Truth

func (e Enum) Truth() starlark.Bool

func (Enum) Type

func (e Enum) Type() string

type List

type List struct {
	// contains filtered or unexported fields
}

List represents a repeated field as a starlark.List.

func (*List) Append

func (l *List) Append(v starlark.Value) error

func (*List) Attr

func (l *List) Attr(name string) (starlark.Value, error)

func (*List) AttrNames

func (l *List) AttrNames() []string

func (*List) Clear

func (l *List) Clear() error

func (*List) Freeze

func (l *List) Freeze()

func (*List) Hash

func (l *List) Hash() (uint32, error)

func (*List) Index

func (l *List) Index(i int) starlark.Value

func (*List) Iterate

func (l *List) Iterate() starlark.Iterator

func (*List) Len

func (l *List) Len() int

func (*List) Pop

func (l *List) Pop(i int) (starlark.Value, error)

func (*List) SetIndex

func (l *List) SetIndex(i int, v starlark.Value) error

func (*List) Slice

func (l *List) Slice(start, end, step int) starlark.Value

Slice copies values to a starlark.List

func (*List) String

func (l *List) String() string

func (*List) Truth

func (l *List) Truth() starlark.Bool

func (*List) Type

func (l *List) Type() string

Type is a typed list.

type Map

type Map struct {
	// contains filtered or unexported fields
}

func (*Map) Attr

func (m *Map) Attr(name string) (starlark.Value, error)

func (*Map) AttrNames

func (m *Map) AttrNames() []string

func (*Map) Clear

func (m *Map) Clear() error

func (*Map) Delete

func (m *Map) Delete(k starlark.Value) (v starlark.Value, found bool, err error)

func (*Map) Freeze

func (m *Map) Freeze()

func (*Map) Get

func (m *Map) Get(k starlark.Value) (v starlark.Value, found bool, err error)

func (*Map) Hash

func (m *Map) Hash() (uint32, error)

func (*Map) Items

func (m *Map) Items() []starlark.Tuple

func (*Map) Iterate

func (m *Map) Iterate() starlark.Iterator

func (*Map) Keys

func (m *Map) Keys() []starlark.Value

func (*Map) Len

func (m *Map) Len() int

func (*Map) SetKey

func (m *Map) SetKey(k, v starlark.Value) error

func (*Map) String

func (m *Map) String() string

func (*Map) Truth

func (m *Map) Truth() starlark.Bool

func (*Map) Type

func (m *Map) Type() string

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents a proto.Message as a starlark.Value.

func MakeMessage

func MakeMessage(msg proto.Message) *Message

func NewMessage

func NewMessage(msg protoreflect.Message, args starlark.Tuple, kwargs []starlark.Tuple) (*Message, error)

NewMessage creates a *Message base on a protobuffer Message with the given starlark args and kwargs. If both args and kwargs are nil the message is unmodified. Args or kwargs are exclusive. Only one arg can be set of type *Message, None, IterableMapping or HasAttrs.

func (*Message) Attr

func (m *Message) Attr(name string) (starlark.Value, error)

Attr returns the value of the specified field.

func (*Message) AttrNames

func (m *Message) AttrNames() []string

AttrNames returns a new sorted list of the message fields.

func (*Message) Binary

func (x *Message) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)

func (*Message) CompareSameType

func (x *Message) CompareSameType(op syntax.Token, y_ starlark.Value, depth int) (bool, error)

func (*Message) DiffSameType

func (x *Message) DiffSameType(y_ starlark.Value) (string, error)

func (*Message) Freeze

func (m *Message) Freeze()

func (*Message) Hash

func (m *Message) Hash() (uint32, error)

func (*Message) ProtoReflect

func (m *Message) ProtoReflect() protoreflect.Message

ProtoReflect implements proto.Message

func (*Message) SetField

func (m *Message) SetField(name string, val starlark.Value) error

func (*Message) String

func (m *Message) String() string

func (*Message) Truth

func (m *Message) Truth() starlark.Bool

func (*Message) Type

func (m *Message) Type() string

type Proto

type Proto struct {
	// contains filtered or unexported fields
}

Proto is a proto module.

func NewProto

func NewProto(resolver protodesc.Resolver) *Proto

func (*Proto) File

func (p *Proto) File(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

File returns the file descriptor for the given path. file(path)

func (*Proto) Marshal

func (p *Proto) Marshal(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Marshal marshals a message to binary string. marhsal(msg, allow_partial=False, deterministic=False, use_cache_size=False)

func (*Proto) MarshalJSON

func (p *Proto) MarshalJSON(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

MarshalJSON marshals a message to json. marshal_json(msg, multiline=False, indent=None, allow_partial=False, use_proto_names=False, use_enum_numbers=False, emit_unpopulated=False)

func (*Proto) MarshalText

func (p *Proto) MarshalText(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

MarshalText marshals a message to text. marshal_text(msg, multiline=False, indent=None, allow_partial=False, emit_unknown=False)

func (*Proto) New

func (p *Proto) New(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

New returns a new descriptor. new(name)

func (*Proto) Unmarshal

func (p *Proto) Unmarshal(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Unmarshal unmarshals a message from binary string. unmarshal(str, msg, merge=False, allow_partial=False, discard_unknown=False)

func (*Proto) UnmarshalJSON

func (p *Proto) UnmarshalJSON(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

UnmarshalJSON unmarshals a json string to a message. unmarshal_json(str, msg, allow_partial=False, discard_unknown=False)

func (*Proto) UnmarshalText

func (p *Proto) UnmarshalText(thread *starlark.Thread, fnname string, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

UnmarshalText unmarshals a text string to a message. unmarshal_text(str, msg, allow_partial=False, discard_unknown=False)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL