2018-10-18 11:06:29 -07:00
|
|
|
// 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.
|
|
|
|
|
2019-05-22 13:42:54 -04:00
|
|
|
package impl
|
2018-10-18 11:06:29 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2019-07-01 13:45:52 -07:00
|
|
|
"strings"
|
2018-10-18 11:06:29 -07:00
|
|
|
"sync"
|
|
|
|
|
2019-07-01 13:45:52 -07:00
|
|
|
"google.golang.org/protobuf/internal/descopts"
|
|
|
|
ptag "google.golang.org/protobuf/internal/encoding/tag"
|
2019-09-30 15:34:27 -07:00
|
|
|
"google.golang.org/protobuf/internal/errors"
|
2019-07-01 13:45:52 -07:00
|
|
|
"google.golang.org/protobuf/internal/filedesc"
|
2019-07-07 01:49:59 -07:00
|
|
|
"google.golang.org/protobuf/internal/strs"
|
2019-06-06 13:01:53 -07:00
|
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
2019-05-13 23:55:40 -07:00
|
|
|
pref "google.golang.org/protobuf/reflect/protoreflect"
|
2020-02-14 16:48:37 -08:00
|
|
|
"google.golang.org/protobuf/runtime/protoiface"
|
2019-09-25 16:51:15 -07:00
|
|
|
piface "google.golang.org/protobuf/runtime/protoiface"
|
2018-10-18 11:06:29 -07:00
|
|
|
)
|
|
|
|
|
2020-04-01 11:47:49 -07:00
|
|
|
// legacyWrapMessage wraps v as a protoreflect.Message,
|
internal/impl: support legacy extension fields
Implement support for extension fields for messages that use the v1
data structures for extensions. The legacyExtensionFields type wraps a
v1 map to implement the v2 protoreflect.KnownFields interface.
Working on this change revealed a bug in the dynamic construction of
message types for protobuf messages that had cyclic dependencies (e.g.,
message Foo has a sub-field of message Bar, and Bar has a sub-field of Foo).
In such a situation, a deadlock occurs because initialization code depends on
the very initialization code that is currently running. To break these cycles,
we make some systematic changes listed in the following paragraphs.
Generally speaking, we separate the logic for construction and wrapping,
where constuction does not recursively rely on dependencies,
while wrapping may recursively inspect dependencies.
Promote the MessageType.MessageOf method as a standalone MessageOf function
that dynamically finds the proper *MessageType to use. We make it such that
MessageType only supports two forms of messages types:
* Those that fully implement the v2 API.
* Those that do not implement the v2 API at all.
This removes support for the hybrid form that was exploited by message_test.go
In impl/message_test.go, switch each message to look more like how future
generated messages will look like. This is done in reaction to the fact that
MessageType.MessageOf no longer exists.
In value/{map,vector}.go, fix Unwrap to return a pointer since the underlying
reflect.Value is addressable reference value, not a pointer value.
In value/convert.go, split the logic apart so that obtaining a v2 type and
wrapping a type as v2 are distinct operations. Wrapping requires further
initialization than simply creating the initial message type, and calling it
during initial construction would lead to a deadlock.
In protoreflect/go_type.go, we switch back to a lazy initialization of GoType
to avoid a deadlock since the user-provided fn may rely on the fact that
prototype.GoMessage returned.
Change-Id: I5dea00e36fe1a9899bd2ac0aed2c8e51d5d87420
Reviewed-on: https://go-review.googlesource.com/c/148826
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-06 13:05:20 -08:00
|
|
|
// where v must be a *struct kind and not implement the v2 API already.
|
2020-04-01 11:47:49 -07:00
|
|
|
func legacyWrapMessage(v reflect.Value) pref.Message {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
t := v.Type()
|
|
|
|
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
|
2019-09-30 15:34:27 -07:00
|
|
|
return aberrantMessage{v: v}
|
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
mt := legacyLoadMessageInfo(t, "")
|
2020-04-01 11:47:49 -07:00
|
|
|
return mt.MessageOf(v.Interface())
|
internal/impl: support legacy extension fields
Implement support for extension fields for messages that use the v1
data structures for extensions. The legacyExtensionFields type wraps a
v1 map to implement the v2 protoreflect.KnownFields interface.
Working on this change revealed a bug in the dynamic construction of
message types for protobuf messages that had cyclic dependencies (e.g.,
message Foo has a sub-field of message Bar, and Bar has a sub-field of Foo).
In such a situation, a deadlock occurs because initialization code depends on
the very initialization code that is currently running. To break these cycles,
we make some systematic changes listed in the following paragraphs.
Generally speaking, we separate the logic for construction and wrapping,
where constuction does not recursively rely on dependencies,
while wrapping may recursively inspect dependencies.
Promote the MessageType.MessageOf method as a standalone MessageOf function
that dynamically finds the proper *MessageType to use. We make it such that
MessageType only supports two forms of messages types:
* Those that fully implement the v2 API.
* Those that do not implement the v2 API at all.
This removes support for the hybrid form that was exploited by message_test.go
In impl/message_test.go, switch each message to look more like how future
generated messages will look like. This is done in reaction to the fact that
MessageType.MessageOf no longer exists.
In value/{map,vector}.go, fix Unwrap to return a pointer since the underlying
reflect.Value is addressable reference value, not a pointer value.
In value/convert.go, split the logic apart so that obtaining a v2 type and
wrapping a type as v2 are distinct operations. Wrapping requires further
initialization than simply creating the initial message type, and calling it
during initial construction would lead to a deadlock.
In protoreflect/go_type.go, we switch back to a lazy initialization of GoType
to avoid a deadlock since the user-provided fn may rely on the fact that
prototype.GoMessage returned.
Change-Id: I5dea00e36fe1a9899bd2ac0aed2c8e51d5d87420
Reviewed-on: https://go-review.googlesource.com/c/148826
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-06 13:05:20 -08:00
|
|
|
}
|
|
|
|
|
2020-06-05 15:31:25 -07:00
|
|
|
// legacyLoadMessageType dynamically loads a protoreflect.Type for t,
|
|
|
|
// where t must be not implement the v2 API already.
|
|
|
|
// The provided name is used if it cannot be determined from the message.
|
|
|
|
func legacyLoadMessageType(t reflect.Type, name pref.FullName) protoreflect.MessageType {
|
|
|
|
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
|
|
|
|
return aberrantMessageType{t}
|
|
|
|
}
|
|
|
|
return legacyLoadMessageInfo(t, name)
|
|
|
|
}
|
|
|
|
|
2019-05-22 13:42:54 -04:00
|
|
|
var legacyMessageTypeCache sync.Map // map[reflect.Type]*MessageInfo
|
2018-10-19 16:27:46 -07:00
|
|
|
|
2019-05-22 13:42:54 -04:00
|
|
|
// legacyLoadMessageInfo dynamically loads a *MessageInfo for t,
|
internal/impl: support legacy extension fields
Implement support for extension fields for messages that use the v1
data structures for extensions. The legacyExtensionFields type wraps a
v1 map to implement the v2 protoreflect.KnownFields interface.
Working on this change revealed a bug in the dynamic construction of
message types for protobuf messages that had cyclic dependencies (e.g.,
message Foo has a sub-field of message Bar, and Bar has a sub-field of Foo).
In such a situation, a deadlock occurs because initialization code depends on
the very initialization code that is currently running. To break these cycles,
we make some systematic changes listed in the following paragraphs.
Generally speaking, we separate the logic for construction and wrapping,
where constuction does not recursively rely on dependencies,
while wrapping may recursively inspect dependencies.
Promote the MessageType.MessageOf method as a standalone MessageOf function
that dynamically finds the proper *MessageType to use. We make it such that
MessageType only supports two forms of messages types:
* Those that fully implement the v2 API.
* Those that do not implement the v2 API at all.
This removes support for the hybrid form that was exploited by message_test.go
In impl/message_test.go, switch each message to look more like how future
generated messages will look like. This is done in reaction to the fact that
MessageType.MessageOf no longer exists.
In value/{map,vector}.go, fix Unwrap to return a pointer since the underlying
reflect.Value is addressable reference value, not a pointer value.
In value/convert.go, split the logic apart so that obtaining a v2 type and
wrapping a type as v2 are distinct operations. Wrapping requires further
initialization than simply creating the initial message type, and calling it
during initial construction would lead to a deadlock.
In protoreflect/go_type.go, we switch back to a lazy initialization of GoType
to avoid a deadlock since the user-provided fn may rely on the fact that
prototype.GoMessage returned.
Change-Id: I5dea00e36fe1a9899bd2ac0aed2c8e51d5d87420
Reviewed-on: https://go-review.googlesource.com/c/148826
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-06 13:05:20 -08:00
|
|
|
// where t must be a *struct kind and not implement the v2 API already.
|
2019-09-04 22:41:40 -07:00
|
|
|
// The provided name is used if it cannot be determined from the message.
|
|
|
|
func legacyLoadMessageInfo(t reflect.Type, name pref.FullName) *MessageInfo {
|
2019-05-22 05:12:36 -04:00
|
|
|
// Fast-path: check if a MessageInfo is cached for this concrete type.
|
2019-05-22 13:42:54 -04:00
|
|
|
if mt, ok := legacyMessageTypeCache.Load(t); ok {
|
|
|
|
return mt.(*MessageInfo)
|
2018-10-19 16:27:46 -07:00
|
|
|
}
|
|
|
|
|
2019-05-22 05:12:36 -04:00
|
|
|
// Slow-path: derive message descriptor and initialize MessageInfo.
|
2019-08-06 15:43:25 -07:00
|
|
|
mi := &MessageInfo{
|
2019-09-04 22:41:40 -07:00
|
|
|
Desc: legacyLoadMessageDesc(t, name),
|
2019-08-06 15:43:25 -07:00
|
|
|
GoReflectType: t,
|
2019-05-22 00:42:45 -04:00
|
|
|
}
|
2019-09-25 16:51:15 -07:00
|
|
|
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
var hasMarshal, hasUnmarshal bool
|
2019-09-25 16:51:15 -07:00
|
|
|
v := reflect.Zero(t).Interface()
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if _, hasMarshal = v.(legacyMarshaler); hasMarshal {
|
2020-01-21 13:29:51 -08:00
|
|
|
mi.methods.Marshal = legacyMarshal
|
2019-11-06 15:29:05 -08:00
|
|
|
|
|
|
|
// We have no way to tell whether the type's Marshal method
|
|
|
|
// supports deterministic serialization or not, but this
|
|
|
|
// preserves the v1 implementation's behavior of always
|
|
|
|
// calling Marshal methods when present.
|
|
|
|
mi.methods.Flags |= piface.SupportMarshalDeterministic
|
2019-09-25 16:51:15 -07:00
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if _, hasUnmarshal = v.(legacyUnmarshaler); hasUnmarshal {
|
2019-09-30 15:34:27 -07:00
|
|
|
mi.methods.Unmarshal = legacyUnmarshal
|
2019-09-25 16:51:15 -07:00
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if _, hasMerge := v.(legacyMerger); hasMerge || (hasMarshal && hasUnmarshal) {
|
2020-02-14 16:48:37 -08:00
|
|
|
mi.methods.Merge = legacyMerge
|
|
|
|
}
|
2019-09-25 16:51:15 -07:00
|
|
|
|
2019-08-06 15:43:25 -07:00
|
|
|
if mi, ok := legacyMessageTypeCache.LoadOrStore(t, mi); ok {
|
|
|
|
return mi.(*MessageInfo)
|
2019-03-19 14:14:29 -07:00
|
|
|
}
|
2019-08-06 15:43:25 -07:00
|
|
|
return mi
|
2018-10-19 16:27:46 -07:00
|
|
|
}
|
|
|
|
|
2019-06-06 13:01:53 -07:00
|
|
|
var legacyMessageDescCache sync.Map // map[reflect.Type]protoreflect.MessageDescriptor
|
2018-10-18 11:06:29 -07:00
|
|
|
|
2019-05-22 13:42:54 -04:00
|
|
|
// LegacyLoadMessageDesc returns an MessageDescriptor derived from the Go type,
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
// which should be a *struct kind and must not implement the v2 API already.
|
2019-03-25 14:41:32 -07:00
|
|
|
//
|
|
|
|
// This is exported for testing purposes.
|
2019-05-22 13:42:54 -04:00
|
|
|
func LegacyLoadMessageDesc(t reflect.Type) pref.MessageDescriptor {
|
2019-09-04 22:41:40 -07:00
|
|
|
return legacyLoadMessageDesc(t, "")
|
|
|
|
}
|
|
|
|
func legacyLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
|
2018-10-18 11:06:29 -07:00
|
|
|
// Fast-path: check if a MessageDescriptor is cached for this concrete type.
|
2019-05-22 13:42:54 -04:00
|
|
|
if mi, ok := legacyMessageDescCache.Load(t); ok {
|
2018-10-18 11:06:29 -07:00
|
|
|
return mi.(pref.MessageDescriptor)
|
|
|
|
}
|
|
|
|
|
2019-06-06 13:01:53 -07:00
|
|
|
// Slow-path: initialize MessageDescriptor from the raw descriptor.
|
2019-09-30 15:34:27 -07:00
|
|
|
mv := reflect.Zero(t).Interface()
|
2018-10-18 11:06:29 -07:00
|
|
|
if _, ok := mv.(pref.ProtoMessage); ok {
|
|
|
|
panic(fmt.Sprintf("%v already implements proto.Message", t))
|
|
|
|
}
|
2019-06-06 13:01:53 -07:00
|
|
|
mdV1, ok := mv.(messageV1)
|
|
|
|
if !ok {
|
2019-09-04 22:41:40 -07:00
|
|
|
return aberrantLoadMessageDesc(t, name)
|
2018-10-18 11:06:29 -07:00
|
|
|
}
|
2019-11-11 16:30:04 -08:00
|
|
|
|
|
|
|
// If this is a dynamic message type where there isn't a 1-1 mapping between
|
|
|
|
// Go and protobuf types, calling the Descriptor method on the zero value of
|
|
|
|
// the message type isn't likely to work. If it panics, swallow the panic and
|
|
|
|
// continue as if the Descriptor method wasn't present.
|
|
|
|
b, idxs := func() ([]byte, []int) {
|
|
|
|
defer func() {
|
|
|
|
recover()
|
|
|
|
}()
|
|
|
|
return mdV1.Descriptor()
|
|
|
|
}()
|
|
|
|
if b == nil {
|
|
|
|
return aberrantLoadMessageDesc(t, name)
|
|
|
|
}
|
2018-10-18 11:06:29 -07:00
|
|
|
|
2019-12-09 14:31:23 -08:00
|
|
|
// If the Go type has no fields, then this might be a proto3 empty message
|
|
|
|
// from before the size cache was added. If there are any fields, check to
|
|
|
|
// see that at least one of them looks like something we generated.
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if t.Elem().Kind() == reflect.Struct {
|
|
|
|
if nfield := t.Elem().NumField(); nfield > 0 {
|
|
|
|
hasProtoField := false
|
|
|
|
for i := 0; i < nfield; i++ {
|
|
|
|
f := t.Elem().Field(i)
|
|
|
|
if f.Tag.Get("protobuf") != "" || f.Tag.Get("protobuf_oneof") != "" || strings.HasPrefix(f.Name, "XXX_") {
|
|
|
|
hasProtoField = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !hasProtoField {
|
|
|
|
return aberrantLoadMessageDesc(t, name)
|
2019-12-09 14:31:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 13:01:53 -07:00
|
|
|
md := legacyLoadFileDesc(b).Messages().Get(idxs[0])
|
|
|
|
for _, i := range idxs[1:] {
|
|
|
|
md = md.Messages().Get(i)
|
2018-10-18 11:06:29 -07:00
|
|
|
}
|
2019-09-04 22:41:40 -07:00
|
|
|
if name != "" && md.FullName() != name {
|
|
|
|
panic(fmt.Sprintf("mismatching message name: got %v, want %v", md.FullName(), name))
|
|
|
|
}
|
2019-06-06 13:01:53 -07:00
|
|
|
if md, ok := legacyMessageDescCache.LoadOrStore(t, md); ok {
|
|
|
|
return md.(protoreflect.MessageDescriptor)
|
2018-10-18 11:06:29 -07:00
|
|
|
}
|
2019-06-06 13:01:53 -07:00
|
|
|
return md
|
2018-10-18 11:06:29 -07:00
|
|
|
}
|
2019-07-01 13:45:52 -07:00
|
|
|
|
2019-07-02 10:51:24 -07:00
|
|
|
var (
|
|
|
|
aberrantMessageDescLock sync.Mutex
|
|
|
|
aberrantMessageDescCache map[reflect.Type]protoreflect.MessageDescriptor
|
|
|
|
)
|
2019-07-01 13:45:52 -07:00
|
|
|
|
2019-09-30 15:34:27 -07:00
|
|
|
// aberrantLoadMessageDesc returns an MessageDescriptor derived from the Go type,
|
2019-07-01 13:45:52 -07:00
|
|
|
// which must not implement protoreflect.ProtoMessage or messageV1.
|
|
|
|
//
|
|
|
|
// This is a best-effort derivation of the message descriptor using the protobuf
|
|
|
|
// tags on the struct fields.
|
2019-09-04 22:41:40 -07:00
|
|
|
func aberrantLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
|
2019-07-02 10:51:24 -07:00
|
|
|
aberrantMessageDescLock.Lock()
|
|
|
|
defer aberrantMessageDescLock.Unlock()
|
|
|
|
if aberrantMessageDescCache == nil {
|
|
|
|
aberrantMessageDescCache = make(map[reflect.Type]protoreflect.MessageDescriptor)
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
2019-09-04 22:41:40 -07:00
|
|
|
return aberrantLoadMessageDescReentrant(t, name)
|
2019-07-02 10:51:24 -07:00
|
|
|
}
|
2019-09-04 22:41:40 -07:00
|
|
|
func aberrantLoadMessageDescReentrant(t reflect.Type, name pref.FullName) pref.MessageDescriptor {
|
2019-07-02 10:51:24 -07:00
|
|
|
// Fast-path: check if an MessageDescriptor is cached for this concrete type.
|
|
|
|
if md, ok := aberrantMessageDescCache[t]; ok {
|
|
|
|
return md
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Slow-path: construct a descriptor from the Go struct type (best-effort).
|
2019-07-02 10:51:24 -07:00
|
|
|
// Cache the MessageDescriptor early on so that we can resolve internal
|
|
|
|
// cyclic references.
|
|
|
|
md := &filedesc.Message{L2: new(filedesc.MessageL2)}
|
2019-09-30 15:34:27 -07:00
|
|
|
md.L0.FullName = aberrantDeriveMessageName(t, name)
|
2019-07-01 13:45:52 -07:00
|
|
|
md.L0.ParentFile = filedesc.SurrogateProto2
|
2019-07-02 10:51:24 -07:00
|
|
|
aberrantMessageDescCache[t] = md
|
2019-07-01 13:45:52 -07:00
|
|
|
|
2019-09-30 15:34:27 -07:00
|
|
|
if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
|
2019-07-01 13:45:52 -07:00
|
|
|
// Try to determine if the message is using proto3 by checking scalars.
|
|
|
|
for i := 0; i < t.Elem().NumField(); i++ {
|
|
|
|
f := t.Elem().Field(i)
|
|
|
|
if tag := f.Tag.Get("protobuf"); tag != "" {
|
|
|
|
switch f.Type.Kind() {
|
|
|
|
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
|
|
|
|
md.L0.ParentFile = filedesc.SurrogateProto3
|
|
|
|
}
|
|
|
|
for _, s := range strings.Split(tag, ",") {
|
|
|
|
if s == "proto3" {
|
|
|
|
md.L0.ParentFile = filedesc.SurrogateProto3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain a list of oneof wrapper types.
|
|
|
|
var oneofWrappers []reflect.Type
|
2020-04-02 10:31:06 -07:00
|
|
|
for _, method := range []string{"XXX_OneofFuncs", "XXX_OneofWrappers"} {
|
|
|
|
if fn, ok := t.MethodByName(method); ok {
|
|
|
|
for _, v := range fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))}) {
|
|
|
|
if vs, ok := v.Interface().([]interface{}); ok {
|
|
|
|
for _, v := range vs {
|
|
|
|
oneofWrappers = append(oneofWrappers, reflect.TypeOf(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain a list of the extension ranges.
|
|
|
|
if fn, ok := t.MethodByName("ExtensionRangeArray"); ok {
|
|
|
|
vs := fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0]
|
|
|
|
for i := 0; i < vs.Len(); i++ {
|
|
|
|
v := vs.Index(i)
|
|
|
|
md.L2.ExtensionRanges.List = append(md.L2.ExtensionRanges.List, [2]pref.FieldNumber{
|
|
|
|
pref.FieldNumber(v.FieldByName("Start").Int()),
|
|
|
|
pref.FieldNumber(v.FieldByName("End").Int() + 1),
|
|
|
|
})
|
|
|
|
md.L2.ExtensionRangeOptions = append(md.L2.ExtensionRangeOptions, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Derive the message fields by inspecting the struct fields.
|
|
|
|
for i := 0; i < t.Elem().NumField(); i++ {
|
|
|
|
f := t.Elem().Field(i)
|
|
|
|
if tag := f.Tag.Get("protobuf"); tag != "" {
|
|
|
|
tagKey := f.Tag.Get("protobuf_key")
|
|
|
|
tagVal := f.Tag.Get("protobuf_val")
|
|
|
|
aberrantAppendField(md, f.Type, tag, tagKey, tagVal)
|
|
|
|
}
|
|
|
|
if tag := f.Tag.Get("protobuf_oneof"); tag != "" {
|
|
|
|
n := len(md.L2.Oneofs.List)
|
|
|
|
md.L2.Oneofs.List = append(md.L2.Oneofs.List, filedesc.Oneof{})
|
|
|
|
od := &md.L2.Oneofs.List[n]
|
|
|
|
od.L0.FullName = md.FullName().Append(pref.Name(tag))
|
|
|
|
od.L0.ParentFile = md.L0.ParentFile
|
|
|
|
od.L0.Parent = md
|
|
|
|
od.L0.Index = n
|
|
|
|
|
|
|
|
for _, t := range oneofWrappers {
|
|
|
|
if t.Implements(f.Type) {
|
|
|
|
f := t.Elem().Field(0)
|
|
|
|
if tag := f.Tag.Get("protobuf"); tag != "" {
|
|
|
|
aberrantAppendField(md, f.Type, tag, "", "")
|
|
|
|
fd := &md.L2.Fields.List[len(md.L2.Fields.List)-1]
|
|
|
|
fd.L1.ContainingOneof = od
|
|
|
|
od.L1.Fields.List = append(od.L1.Fields.List, fd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return md
|
|
|
|
}
|
|
|
|
|
2019-09-04 22:41:40 -07:00
|
|
|
func aberrantDeriveMessageName(t reflect.Type, name pref.FullName) pref.FullName {
|
|
|
|
if name.IsValid() {
|
|
|
|
return name
|
|
|
|
}
|
2019-09-10 12:20:00 -07:00
|
|
|
func() {
|
|
|
|
defer func() { recover() }() // swallow possible nil panics
|
2019-09-30 15:34:27 -07:00
|
|
|
if m, ok := reflect.Zero(t).Interface().(interface{ XXX_MessageName() string }); ok {
|
2019-09-10 12:20:00 -07:00
|
|
|
name = pref.FullName(m.XXX_MessageName())
|
2019-09-04 22:41:40 -07:00
|
|
|
}
|
2019-09-10 12:20:00 -07:00
|
|
|
}()
|
|
|
|
if name.IsValid() {
|
|
|
|
return name
|
2019-09-04 22:41:40 -07:00
|
|
|
}
|
2019-09-30 15:34:27 -07:00
|
|
|
if t.Kind() == reflect.Ptr {
|
|
|
|
t = t.Elem()
|
|
|
|
}
|
2020-01-11 00:25:01 -08:00
|
|
|
return AberrantDeriveFullName(t)
|
2019-09-04 22:41:40 -07:00
|
|
|
}
|
|
|
|
|
2019-07-01 13:45:52 -07:00
|
|
|
func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey, tagVal string) {
|
|
|
|
t := goType
|
|
|
|
isOptional := t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct
|
|
|
|
isRepeated := t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
|
|
|
|
if isOptional || isRepeated {
|
|
|
|
t = t.Elem()
|
|
|
|
}
|
|
|
|
fd := ptag.Unmarshal(tag, t, placeholderEnumValues{}).(*filedesc.Field)
|
|
|
|
|
|
|
|
// Append field descriptor to the message.
|
|
|
|
n := len(md.L2.Fields.List)
|
|
|
|
md.L2.Fields.List = append(md.L2.Fields.List, *fd)
|
|
|
|
fd = &md.L2.Fields.List[n]
|
|
|
|
fd.L0.FullName = md.FullName().Append(fd.Name())
|
|
|
|
fd.L0.ParentFile = md.L0.ParentFile
|
|
|
|
fd.L0.Parent = md
|
|
|
|
fd.L0.Index = n
|
|
|
|
|
|
|
|
if fd.L1.IsWeak || fd.L1.HasPacked {
|
|
|
|
fd.L1.Options = func() pref.ProtoMessage {
|
|
|
|
opts := descopts.Field.ProtoReflect().New()
|
|
|
|
if fd.L1.IsWeak {
|
2019-09-17 13:38:48 -07:00
|
|
|
opts.Set(opts.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
|
|
|
if fd.L1.HasPacked {
|
2019-09-17 13:38:48 -07:00
|
|
|
opts.Set(opts.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(fd.L1.IsPacked))
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
|
|
|
return opts.Interface()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate Enum and Message.
|
|
|
|
if fd.Enum() == nil && fd.Kind() == pref.EnumKind {
|
|
|
|
switch v := reflect.Zero(t).Interface().(type) {
|
|
|
|
case pref.Enum:
|
|
|
|
fd.L1.Enum = v.Descriptor()
|
|
|
|
default:
|
|
|
|
fd.L1.Enum = LegacyLoadEnumDesc(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if fd.Message() == nil && (fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind) {
|
|
|
|
switch v := reflect.Zero(t).Interface().(type) {
|
|
|
|
case pref.ProtoMessage:
|
|
|
|
fd.L1.Message = v.ProtoReflect().Descriptor()
|
2019-07-02 10:51:24 -07:00
|
|
|
case messageV1:
|
|
|
|
fd.L1.Message = LegacyLoadMessageDesc(t)
|
2019-07-01 13:45:52 -07:00
|
|
|
default:
|
|
|
|
if t.Kind() == reflect.Map {
|
|
|
|
n := len(md.L1.Messages.List)
|
|
|
|
md.L1.Messages.List = append(md.L1.Messages.List, filedesc.Message{L2: new(filedesc.MessageL2)})
|
|
|
|
md2 := &md.L1.Messages.List[n]
|
2019-07-07 01:49:59 -07:00
|
|
|
md2.L0.FullName = md.FullName().Append(pref.Name(strs.MapEntryName(string(fd.Name()))))
|
2019-07-01 13:45:52 -07:00
|
|
|
md2.L0.ParentFile = md.L0.ParentFile
|
|
|
|
md2.L0.Parent = md
|
|
|
|
md2.L0.Index = n
|
|
|
|
|
2019-11-07 15:30:44 -08:00
|
|
|
md2.L1.IsMapEntry = true
|
2019-07-01 13:45:52 -07:00
|
|
|
md2.L2.Options = func() pref.ProtoMessage {
|
|
|
|
opts := descopts.Message.ProtoReflect().New()
|
2019-09-17 13:38:48 -07:00
|
|
|
opts.Set(opts.Descriptor().Fields().ByName("map_entry"), protoreflect.ValueOfBool(true))
|
2019-07-01 13:45:52 -07:00
|
|
|
return opts.Interface()
|
|
|
|
}
|
|
|
|
|
|
|
|
aberrantAppendField(md2, t.Key(), tagKey, "", "")
|
|
|
|
aberrantAppendField(md2, t.Elem(), tagVal, "", "")
|
|
|
|
|
|
|
|
fd.L1.Message = md2
|
|
|
|
break
|
|
|
|
}
|
2019-09-04 22:41:40 -07:00
|
|
|
fd.L1.Message = aberrantLoadMessageDescReentrant(t, "")
|
2019-07-01 13:45:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type placeholderEnumValues struct {
|
|
|
|
protoreflect.EnumValueDescriptors
|
|
|
|
}
|
|
|
|
|
|
|
|
func (placeholderEnumValues) ByNumber(n pref.EnumNumber) pref.EnumValueDescriptor {
|
|
|
|
return filedesc.PlaceholderEnumValue(pref.FullName(fmt.Sprintf("UNKNOWN_%d", n)))
|
|
|
|
}
|
2019-09-30 15:34:27 -07:00
|
|
|
|
|
|
|
// legacyMarshaler is the proto.Marshaler interface superseded by protoiface.Methoder.
|
|
|
|
type legacyMarshaler interface {
|
|
|
|
Marshal() ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// legacyUnmarshaler is the proto.Unmarshaler interface superseded by protoiface.Methoder.
|
|
|
|
type legacyUnmarshaler interface {
|
|
|
|
Unmarshal([]byte) error
|
|
|
|
}
|
|
|
|
|
2020-02-14 16:48:37 -08:00
|
|
|
// legacyMerger is the proto.Merger interface superseded by protoiface.Methoder.
|
|
|
|
type legacyMerger interface {
|
|
|
|
Merge(protoiface.MessageV1)
|
|
|
|
}
|
|
|
|
|
2020-07-27 12:44:43 -07:00
|
|
|
var aberrantProtoMethods = &piface.Methods{
|
2020-01-21 13:29:51 -08:00
|
|
|
Marshal: legacyMarshal,
|
|
|
|
Unmarshal: legacyUnmarshal,
|
2020-02-14 16:48:37 -08:00
|
|
|
Merge: legacyMerge,
|
2019-11-06 15:29:05 -08:00
|
|
|
|
|
|
|
// We have no way to tell whether the type's Marshal method
|
|
|
|
// supports deterministic serialization or not, but this
|
|
|
|
// preserves the v1 implementation's behavior of always
|
|
|
|
// calling Marshal methods when present.
|
|
|
|
Flags: piface.SupportMarshalDeterministic,
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:49:35 -08:00
|
|
|
func legacyMarshal(in piface.MarshalInput) (piface.MarshalOutput, error) {
|
|
|
|
v := in.Message.(unwrapper).protoUnwrap()
|
2019-09-30 15:34:27 -07:00
|
|
|
marshaler, ok := v.(legacyMarshaler)
|
|
|
|
if !ok {
|
2020-01-21 13:29:51 -08:00
|
|
|
return piface.MarshalOutput{}, errors.New("%T does not implement Marshal", v)
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
out, err := marshaler.Marshal()
|
2020-01-21 13:29:51 -08:00
|
|
|
if in.Buf != nil {
|
|
|
|
out = append(in.Buf, out...)
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
2020-01-21 13:29:51 -08:00
|
|
|
return piface.MarshalOutput{
|
|
|
|
Buf: out,
|
|
|
|
}, err
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:49:35 -08:00
|
|
|
func legacyUnmarshal(in piface.UnmarshalInput) (piface.UnmarshalOutput, error) {
|
|
|
|
v := in.Message.(unwrapper).protoUnwrap()
|
2019-09-30 15:34:27 -07:00
|
|
|
unmarshaler, ok := v.(legacyUnmarshaler)
|
|
|
|
if !ok {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
return piface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", v)
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
2020-01-21 13:29:51 -08:00
|
|
|
return piface.UnmarshalOutput{}, unmarshaler.Unmarshal(in.Buf)
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:49:35 -08:00
|
|
|
func legacyMerge(in piface.MergeInput) piface.MergeOutput {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
// Check whether this supports the legacy merger.
|
2020-02-14 14:49:35 -08:00
|
|
|
dstv := in.Destination.(unwrapper).protoUnwrap()
|
2020-02-14 16:48:37 -08:00
|
|
|
merger, ok := dstv.(legacyMerger)
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if ok {
|
|
|
|
merger.Merge(Export{}.ProtoMessageV1Of(in.Source))
|
|
|
|
return piface.MergeOutput{Flags: piface.MergeComplete}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If legacy merger is unavailable, implement merge in terms of
|
|
|
|
// a marshal and unmarshal operation.
|
|
|
|
srcv := in.Source.(unwrapper).protoUnwrap()
|
|
|
|
marshaler, ok := srcv.(legacyMarshaler)
|
2020-02-14 16:48:37 -08:00
|
|
|
if !ok {
|
|
|
|
return piface.MergeOutput{}
|
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
dstv = in.Destination.(unwrapper).protoUnwrap()
|
|
|
|
unmarshaler, ok := dstv.(legacyUnmarshaler)
|
|
|
|
if !ok {
|
|
|
|
return piface.MergeOutput{}
|
|
|
|
}
|
2021-05-20 10:35:18 -07:00
|
|
|
if !in.Source.IsValid() {
|
|
|
|
// Legacy Marshal methods may not function on nil messages.
|
|
|
|
// Check for a typed nil source only after we confirm that
|
|
|
|
// legacy Marshal/Unmarshal methods are present, for
|
|
|
|
// consistency.
|
|
|
|
return piface.MergeOutput{Flags: piface.MergeComplete}
|
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
b, err := marshaler.Marshal()
|
|
|
|
if err != nil {
|
|
|
|
return piface.MergeOutput{}
|
|
|
|
}
|
|
|
|
err = unmarshaler.Unmarshal(b)
|
|
|
|
if err != nil {
|
|
|
|
return piface.MergeOutput{}
|
|
|
|
}
|
2020-02-14 14:49:35 -08:00
|
|
|
return piface.MergeOutput{Flags: piface.MergeComplete}
|
2020-02-14 16:48:37 -08:00
|
|
|
}
|
|
|
|
|
2019-09-30 15:34:27 -07:00
|
|
|
// aberrantMessageType implements MessageType for all types other than pointer-to-struct.
|
|
|
|
type aberrantMessageType struct {
|
|
|
|
t reflect.Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mt aberrantMessageType) New() pref.Message {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if mt.t.Kind() == reflect.Ptr {
|
|
|
|
return aberrantMessage{reflect.New(mt.t.Elem())}
|
|
|
|
}
|
2019-09-30 15:34:27 -07:00
|
|
|
return aberrantMessage{reflect.Zero(mt.t)}
|
|
|
|
}
|
|
|
|
func (mt aberrantMessageType) Zero() pref.Message {
|
|
|
|
return aberrantMessage{reflect.Zero(mt.t)}
|
|
|
|
}
|
|
|
|
func (mt aberrantMessageType) GoType() reflect.Type {
|
|
|
|
return mt.t
|
|
|
|
}
|
|
|
|
func (mt aberrantMessageType) Descriptor() pref.MessageDescriptor {
|
|
|
|
return LegacyLoadMessageDesc(mt.t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// aberrantMessage implements Message for all types other than pointer-to-struct.
|
|
|
|
//
|
|
|
|
// When the underlying type implements legacyMarshaler or legacyUnmarshaler,
|
|
|
|
// the aberrant Message can be marshaled or unmarshaled. Otherwise, there is
|
|
|
|
// not much that can be done with values of this type.
|
|
|
|
type aberrantMessage struct {
|
|
|
|
v reflect.Value
|
|
|
|
}
|
|
|
|
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
// Reset implements the v1 proto.Message.Reset method.
|
|
|
|
func (m aberrantMessage) Reset() {
|
|
|
|
if mr, ok := m.v.Interface().(interface{ Reset() }); ok {
|
|
|
|
mr.Reset()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if m.v.Kind() == reflect.Ptr && !m.v.IsNil() {
|
|
|
|
m.v.Elem().Set(reflect.Zero(m.v.Type().Elem()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-30 15:34:27 -07:00
|
|
|
func (m aberrantMessage) ProtoReflect() pref.Message {
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m aberrantMessage) Descriptor() pref.MessageDescriptor {
|
|
|
|
return LegacyLoadMessageDesc(m.v.Type())
|
|
|
|
}
|
|
|
|
func (m aberrantMessage) Type() pref.MessageType {
|
|
|
|
return aberrantMessageType{m.v.Type()}
|
|
|
|
}
|
|
|
|
func (m aberrantMessage) New() pref.Message {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if m.v.Type().Kind() == reflect.Ptr {
|
|
|
|
return aberrantMessage{reflect.New(m.v.Type().Elem())}
|
|
|
|
}
|
2019-09-30 15:34:27 -07:00
|
|
|
return aberrantMessage{reflect.Zero(m.v.Type())}
|
|
|
|
}
|
|
|
|
func (m aberrantMessage) Interface() pref.ProtoMessage {
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
func (m aberrantMessage) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
return
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) Has(pref.FieldDescriptor) bool {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
return false
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) Clear(pref.FieldDescriptor) {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
panic("invalid Message.Clear on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
func (m aberrantMessage) Get(fd pref.FieldDescriptor) pref.Value {
|
|
|
|
if fd.Default().IsValid() {
|
|
|
|
return fd.Default()
|
|
|
|
}
|
|
|
|
panic("invalid Message.Get on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) Set(pref.FieldDescriptor, pref.Value) {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
panic("invalid Message.Set on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) Mutable(pref.FieldDescriptor) pref.Value {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
panic("invalid Message.Mutable on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) NewField(pref.FieldDescriptor) pref.Value {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
panic("invalid Message.NewField on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) WhichOneof(pref.OneofDescriptor) pref.FieldDescriptor {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
panic("invalid Message.WhichOneof descriptor on " + string(m.Descriptor().FullName()))
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) GetUnknown() pref.RawFields {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (m aberrantMessage) SetUnknown(pref.RawFields) {
|
|
|
|
// SetUnknown discards its input on messages which don't support unknown field storage.
|
|
|
|
}
|
2019-11-26 13:27:24 -08:00
|
|
|
func (m aberrantMessage) IsValid() bool {
|
internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.
In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.
This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.
The only types that still do not fully work are:
* "k8s.io/api/authentication/v1".ExtraValue
* "k8s.io/api/authentication/v1beta1".ExtraValue
* "k8s.io/api/authorization/v1".ExtraValue
* "k8s.io/api/authorization/v1beta1".ExtraValue
* "k8s.io/api/certificates/v1".ExtraValue
* "k8s.io/api/certificates/v1beta1".ExtraValue
* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.
Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 02:50:41 -08:00
|
|
|
if m.v.Kind() == reflect.Ptr {
|
|
|
|
return !m.v.IsNil()
|
|
|
|
}
|
|
|
|
return false
|
2019-11-26 13:27:24 -08:00
|
|
|
}
|
2019-09-30 15:34:27 -07:00
|
|
|
func (m aberrantMessage) ProtoMethods() *piface.Methods {
|
2020-07-27 12:44:43 -07:00
|
|
|
return aberrantProtoMethods
|
2019-09-30 15:34:27 -07:00
|
|
|
}
|
|
|
|
func (m aberrantMessage) protoUnwrap() interface{} {
|
|
|
|
return m.v.Interface()
|
|
|
|
}
|