starlarkproto

package module
v0.0.0-...-d6b8da9 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

README

starlarkproto

GoDev

Supports protobuffers in starlark!

test = proto.file("github.com/afking/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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModule

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

Types

type Descriptor

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

func NewDescriptor

func NewDescriptor(desc protoreflect.Descriptor) *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)

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 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 NewMessage

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

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) 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
}

func NewProto

func NewProto(resolver protodesc.Resolver) *Proto

func (*Proto) File

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

func (*Proto) Marshal

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

func (*Proto) MarshalJSON

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

func (*Proto) MarshalText

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

func (*Proto) New

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

func (*Proto) Unmarshal

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

func (*Proto) UnmarshalJSON

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

func (*Proto) UnmarshalText

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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