chain_proto

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: Apache-2.0 Imports: 4 Imported by: 9

README

chain-proto

Extensions to gogoprotobuf for chain.

accepts_interface

An informational extension to be added to google.protobuf.Any fields to indicate which interface that field accepts. The interface name should be independent of any programming language and either be unqualified to indicate the current package of fully-qualified to indicate another protobuf package.

Example:

message SomeContainer {
    google.protobuf.Any some_interface = 1 [(chain_proto.accepts_interface) = "SomeInterface"];
}

message AnotherContainer {
    google.protobuf.Any another_interface = 1 [(chain_proto.accepts_interface) = "another.package.AnotherInterface"];
}

implements_interface

An informational extension to be added to messages to indicate which interface that message implements. The interface name should be independent of any programming language and either be unqualified to indicate the current package of fully-qualified to indicate another protobuf package.

message A {
    option (chain_proto.implements_interface) = "SomeInterface";
    int64 x = 1;
}

message B {
    option (chain_proto.implements_interface) = "another.package.AnotherInterface";
    double x = 1;
}

interface_type

See test for a full example.

The chain_proto.interface_type message option generates a getter and setter from the provided go interface. Messages which use this option must consist of a single oneof and no other fields.

Given this example .proto file:

message ABC {
    option (chain_proto.interface_type) = "my_package.Msg";
    oneof abc {
        A a = 1;
        B b = 2;
        C c = 3;
    }
}

message A { int32 x = 1; }

message B { uint32 y = 1; }

message C { bool z = 1; }

The ABC struct will satisfy the following interface:

type MsgCodec interface {
    GetMsg() Msg
    SetMsg(value Msg) error
}

The types A, B, and C must of course have implementations of Msg.

Handling Non-Pointer Interfaces

By default interface_type generates Set handlers for both pointer and non-pointer implementations of an interface (i.e. both *A and A). This means all interfaces must be implemented for the non-pointer version of a struct. To disable the non-pointer cases (so that just *A and not A needs to implement the interface), the interface type name can be prepended with a *, ex: option (chain_proto.interface_type) = "*my_package.Msg";.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var E_AcceptsInterface = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.FieldOptions)(nil),
	ExtensionType: (*string)(nil),
	Field:         93001,
	Name:          "chain_proto.accepts_interface",
	Tag:           "bytes,93001,opt,name=accepts_interface",
	Filename:      "chain.proto",
}
View Source
var E_ImplementsInterface = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.MessageOptions)(nil),
	ExtensionType: (*string)(nil),
	Field:         93002,
	Name:          "chain_proto.implements_interface",
	Tag:           "bytes,93002,opt,name=implements_interface",
	Filename:      "chain.proto",
}
View Source
var E_InterfaceType = &proto.ExtensionDesc{
	ExtendedType:  (*descriptor.MessageOptions)(nil),
	ExtensionType: (*string)(nil),
	Field:         93001,
	Name:          "chain_proto.interface_type",
	Tag:           "bytes,93001,opt,name=interface_type",
	Filename:      "chain.proto",
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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