blob: f1fe5aafca6082b8d3e6f0148145cd12e93e6a28 [file] [log] [blame]
Herbie Ongcddf8192018-11-28 18:25:20 -08001// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package proto
6
Damien Neil0d3e8cc2019-04-01 13:31:55 -07007import (
Damien Neil96c229a2019-04-03 12:17:24 -07008 "github.com/golang/protobuf/v2/internal/errors"
Damien Neil0d3e8cc2019-04-01 13:31:55 -07009 "github.com/golang/protobuf/v2/reflect/protoreflect"
10 "github.com/golang/protobuf/v2/runtime/protoiface"
11)
Herbie Ongcddf8192018-11-28 18:25:20 -080012
13// Message is the top-level interface that all messages must implement.
14type Message = protoreflect.ProtoMessage
Damien Neil0d3e8cc2019-04-01 13:31:55 -070015
16// errInternalNoFast indicates that fast-path operations are not available for a message.
Damien Neil96c229a2019-04-03 12:17:24 -070017var errInternalNoFast = errors.New("BUG: internal error (errInternalNoFast)")
Damien Neil0d3e8cc2019-04-01 13:31:55 -070018
19func protoMethods(m Message) *protoiface.Methods {
20 if x, ok := m.(protoiface.Methoder); ok {
21 return x.XXX_Methods()
22 }
23 return nil
24}
Damien Neil96c229a2019-04-03 12:17:24 -070025
26func checkRequiredFields(m protoreflect.Message, nerr *errors.NonFatal) {
27 req := m.Type().RequiredNumbers()
28 knownFields := m.KnownFields()
29 for i, reqLen := 0, req.Len(); i < reqLen; i++ {
30 num := req.Get(i)
31 if !knownFields.Has(num) {
32 nerr.AppendRequiredNotSet(string(m.Type().Fields().ByNumber(num).FullName()))
33 }
34 }
35}