protobuf-go/proto/proto.go
Damien Neil 0d3e8cc096 proto, runtime/protoiface: add support for fast-path marshaling
Allow message implementations to provide optimized versions of standard
operations. Generated messages now include a ProtoReflectMethods method,
returning a protoiface.Methods struct containing pointers to assorted
optional functions.

The Methods struct also includes a Flags field indicating support for
optional features such as deterministic marshaling.

Implementation of the fast paths (and tests) will come in later CLs.

Change-Id: Idd1beed0ecf43ec5e5e7b8da2ee1e08d3ce32213
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/170340
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-04-02 21:23:04 +00:00

26 lines
730 B
Go

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package proto
import (
"errors"
"github.com/golang/protobuf/v2/reflect/protoreflect"
"github.com/golang/protobuf/v2/runtime/protoiface"
)
// Message is the top-level interface that all messages must implement.
type Message = protoreflect.ProtoMessage
// errInternalNoFast indicates that fast-path operations are not available for a message.
var errInternalNoFast = errors.New("proto: BUG: internal error (errInternalNoFast)")
func protoMethods(m Message) *protoiface.Methods {
if x, ok := m.(protoiface.Methoder); ok {
return x.XXX_Methods()
}
return nil
}