Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 1 | // 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 | |
| 5 | package proto |
| 6 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 7 | import ( |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame^] | 8 | "github.com/golang/protobuf/v2/internal/errors" |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 9 | "github.com/golang/protobuf/v2/reflect/protoreflect" |
| 10 | "github.com/golang/protobuf/v2/runtime/protoiface" |
| 11 | ) |
Herbie Ong | cddf819 | 2018-11-28 18:25:20 -0800 | [diff] [blame] | 12 | |
| 13 | // Message is the top-level interface that all messages must implement. |
| 14 | type Message = protoreflect.ProtoMessage |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 15 | |
| 16 | // errInternalNoFast indicates that fast-path operations are not available for a message. |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame^] | 17 | var errInternalNoFast = errors.New("BUG: internal error (errInternalNoFast)") |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 18 | |
| 19 | func protoMethods(m Message) *protoiface.Methods { |
| 20 | if x, ok := m.(protoiface.Methoder); ok { |
| 21 | return x.XXX_Methods() |
| 22 | } |
| 23 | return nil |
| 24 | } |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame^] | 25 | |
| 26 | func 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 | } |