github.com/googleapis/gnostic v0.4.1

This commit is contained in:
Jordan Liggitt
2020-03-31 17:18:56 -04:00
parent dda530cfb7
commit 93c7b24562
95 changed files with 6306 additions and 5292 deletions

View File

@@ -165,6 +165,11 @@ type wkt interface {
XXX_WellKnownType() string
}
var (
wktType = reflect.TypeOf((*wkt)(nil)).Elem()
messageType = reflect.TypeOf((*proto.Message)(nil)).Elem()
)
// marshalObject writes a struct to the Writer.
func (m *Marshaler) marshalObject(out *errWriter, v proto.Message, indent, typeURL string) error {
if jsm, ok := v.(JSONPBMarshaler); ok {
@@ -531,7 +536,8 @@ func (m *Marshaler) marshalValue(out *errWriter, prop *proto.Properties, v refle
// Handle well-known types.
// Most are handled up in marshalObject (because 99% are messages).
if wkt, ok := v.Interface().(wkt); ok {
if v.Type().Implements(wktType) {
wkt := v.Interface().(wkt)
switch wkt.XXX_WellKnownType() {
case "NullValue":
out.write("null")
@@ -1277,8 +1283,8 @@ func checkRequiredFields(pb proto.Message) error {
}
func checkRequiredFieldsInValue(v reflect.Value) error {
if pm, ok := v.Interface().(proto.Message); ok {
return checkRequiredFields(pm)
if v.Type().Implements(messageType) {
return checkRequiredFields(v.Interface().(proto.Message))
}
return nil
}

View File

@@ -393,7 +393,7 @@ func (p *Buffer) Bytes() []byte { return p.buf }
// than relying on this API.
//
// If deterministic serialization is requested, map entries will be sorted
// by keys in lexographical order. This is an implementation detail and
// by keys in lexicographical order. This is an implementation detail and
// subject to change.
func (p *Buffer) SetDeterministic(deterministic bool) {
p.deterministic = deterministic

View File

@@ -456,6 +456,8 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
return nil
}
var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
// writeAny writes an arbitrary field.
func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
v = reflect.Indirect(v)
@@ -519,8 +521,8 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert
// mutating this value.
v = v.Addr()
}
if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
text, err := etm.MarshalText()
if v.Type().Implements(textMarshalerType) {
text, err := v.Interface().(encoding.TextMarshaler).MarshalText()
if err != nil {
return err
}

View File

@@ -2062,7 +2062,7 @@ func (g *Generator) generateInternalStructFields(mc *msgCtx, topLevelFields []to
}
// generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer.
// generateOneofFuncs adds all the utility functions for oneof, including marshaling, unmarshaling and sizer.
func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelField) {
ofields := []*oneofField{}
for _, f := range topLevelFields {

View File

@@ -47,7 +47,7 @@ type Location struct {
}
// A Map represents a mapping between token locations in an input source text
// and locations in the correspnding output text.
// and locations in the corresponding output text.
type Map map[Location]Location
// Find reports whether the specified span is recorded by m, and if so returns