value

package
v2.0.0-...-d24bc72 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2019 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package value provides functionality for wrapping Go values to implement protoreflect values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListOf

func ListOf(p interface{}, c Converter) interface {
	pref.List
	Unwrapper
}

func MapOf

func MapOf(p interface{}, kc, kv Converter) interface {
	pref.Map
	Unwrapper
}

Types

type Converter

type Converter struct {
	PBValueOf   func(reflect.Value) pref.Value
	GoValueOf   func(pref.Value) reflect.Value
	EnumType    pref.EnumType
	MessageType pref.MessageType
	IsLegacy    bool
}

Converter provides functions for converting to/from Go reflect.Value types and protobuf protoreflect.Value types.

func NewConverter

func NewConverter(t reflect.Type, k pref.Kind) Converter

NewConverter matches a Go type with a protobuf kind and returns a Converter that converts between the two. NewConverter panics if it unable to provide a conversion between the two. The Converter methods also panic when they are called on incorrect Go types.

This matcher deliberately supports a wider range of Go types than what protoc-gen-go historically generated to be able to automatically wrap some v1 messages generated by other forks of protoc-gen-go.

func NewLegacyConverter

func NewLegacyConverter(t reflect.Type, k pref.Kind, w LegacyWrapper) Converter

NewLegacyConverter is identical to NewConverter, but supports wrapping legacy v1 messages to implement the v2 message API using the provided LegacyWrapper.

type LegacyEnum

type LegacyEnum = interface {
	pref.Enum
	ProtoUnwrap() interface{}
}

LegacyWrapper is a set of wrapper methods that wraps legacy v1 Go types to implement the v2 reflection APIs.

type LegacyMessage

type LegacyMessage = interface {
	pref.Message
	ProtoUnwrap() interface{}
}

LegacyWrapper is a set of wrapper methods that wraps legacy v1 Go types to implement the v2 reflection APIs.

type LegacyWrapper

type LegacyWrapper interface {
	EnumOf(interface{}) LegacyEnum
	EnumTypeOf(interface{}) pref.EnumType

	MessageOf(interface{}) LegacyMessage
	MessageTypeOf(interface{}) pref.MessageType

	ExtensionTypeOf(pref.ExtensionDescriptor, interface{}) pref.ExtensionType

	// TODO: Remove these eventually.
	// See the TODOs in internal/impl/legacy_extension.go.
	ExtensionDescFromType(pref.ExtensionType) *piface.ExtensionDescV1
	ExtensionTypeFromDesc(*piface.ExtensionDescV1) pref.ExtensionType
}

LegacyWrapper is a set of wrapper methods that wraps legacy v1 Go types to implement the v2 reflection APIs.

type Unwrapper

type Unwrapper interface {
	ProtoUnwrap() interface{}
}

Unwrapper unwraps the value to the underlying value. This is implemented by List and Map.

Jump to

Keyboard shortcuts

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