pb

package
v0.208.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdProtobufDecoder = rel.NewNativeFunction("decode", func(_ context.Context, param rel.Value) (rel.Value, error) {
	tuple, isTuple := param.(rel.Tuple)
	if !isTuple {
		return nil, fmt.Errorf("//encoding.proto.decode: param not tuple")
	}

	fdVal, found := tuple.Get(fileDescriptorSet)
	if !found {
		return nil, fmt.Errorf("//encoding.proto.decode: couldn't find %s in tuple", fileDescriptorSet)
	}
	fdBytes, isBytes := fdVal.(rel.Bytes)
	if !isBytes {
		return nil, fmt.Errorf("//encoding.proto.decode: %s is not bytes", fileDescriptorSet)
	}
	fd, err := decodeFileDescriptor(fdBytes.Bytes())
	if err != nil {
		return nil, err
	}

	return rel.NewNativeFunction("decode$2", func(_ context.Context, messageTypeName rel.Value) (rel.Value, error) {
		nameStr, isStr := tools.ValueAsString(messageTypeName)
		if !isStr {
			return nil, fmt.Errorf("//encoding.proto.decode: messageTypeName not string")
		}
		rootMessageDesc := fd.Messages().ByName(protoreflect.Name(nameStr))
		message := dynamicpb.NewMessage(rootMessageDesc)

		return rel.NewNativeFunction("decode$3", func(_ context.Context, data rel.Value) (rel.Value, error) {
			dataBytes, is := tools.ValueAsBytes(data)
			if !is {
				return nil, fmt.Errorf("//encoding.proto.decode: data not bytes")
			}

			err := proto.Unmarshal(dataBytes, message)
			if err != nil {
				return nil, err
			}

			tuple, err := convertProtoValToSyslVal(protoreflect.ValueOf(message.ProtoReflect()))
			if err != nil {
				return nil, err
			}

			return tuple, nil
		}), nil
	}), nil
})

StdProtobufDecoder transforms the protocol buffer message to a tuple.

View Source
var StdProtobufDescriptor = rel.NewNativeFunction(
	"decode",
	func(_ context.Context, param rel.Value) (rel.Value, error) {
		definitionBytes, isBytes := param.(rel.Bytes)
		if !isBytes {
			return nil, fmt.Errorf("//encoding.proto.descriptor: param not bytes")
		}

		return rel.NewTuple(rel.NewAttr(fileDescriptorSet, definitionBytes)), nil
	},
)

StdProtobufDescriptor transforms the protocol buffer `.proto` binary file to a tuple.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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