|
|
@@ -41,6 +41,9 @@ import (
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
+// ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message.
|
|
|
+var ErrMissingExtension = errors.New("proto: missing extension")
|
|
|
+
|
|
|
// ExtensionRange represents a range of message extensions for a protocol buffer.
|
|
|
// Used in code generated by the protocol compiler.
|
|
|
type ExtensionRange struct {
|
|
|
@@ -153,7 +156,7 @@ func ClearExtension(pb extendableProto, extension *ExtensionDesc) {
|
|
|
}
|
|
|
|
|
|
// GetExtension parses and returns the given extension of pb.
|
|
|
-// If the extension is not present it returns (nil, nil).
|
|
|
+// If the extension is not present it returns ErrMissingExtension.
|
|
|
func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
|
|
|
if err := checkExtensionTypes(pb, extension); err != nil {
|
|
|
return nil, err
|
|
|
@@ -161,7 +164,7 @@ func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, er
|
|
|
|
|
|
e, ok := pb.ExtensionMap()[extension.Field]
|
|
|
if !ok {
|
|
|
- return nil, nil // not an error
|
|
|
+ return nil, ErrMissingExtension
|
|
|
}
|
|
|
if e.value != nil {
|
|
|
// Already decoded. Check the descriptor, though.
|