reflect/protoreflect: print unknown number in String methods

Preserving the unknown enum in the String method helps errors
produced by reflect/protodesc be more informative.

Change-Id: I8efb09cb3c744bf4483b310053df7686da540387
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/183699
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-06-24 16:03:52 -07:00 committed by Joe Tsai
parent 2fc306a8e3
commit 1ffc47f77e

View File

@ -27,6 +27,7 @@
package protoreflect package protoreflect
import ( import (
"fmt"
"regexp" "regexp"
"strings" "strings"
@ -69,7 +70,7 @@ func (s Syntax) String() string {
case Proto3: case Proto3:
return "proto3" return "proto3"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", s)
} }
} }
@ -81,7 +82,7 @@ func (s Syntax) GoString() string {
case Proto3: case Proto3:
return "Proto3" return "Proto3"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", s)
} }
} }
@ -117,7 +118,7 @@ func (c Cardinality) String() string {
case Repeated: case Repeated:
return "repeated" return "repeated"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", c)
} }
} }
@ -131,7 +132,7 @@ func (c Cardinality) GoString() string {
case Repeated: case Repeated:
return "Repeated" return "Repeated"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", c)
} }
} }
@ -217,7 +218,7 @@ func (k Kind) String() string {
case GroupKind: case GroupKind:
return "group" return "group"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", k)
} }
} }
@ -261,7 +262,7 @@ func (k Kind) GoString() string {
case GroupKind: case GroupKind:
return "GroupKind" return "GroupKind"
default: default:
return "<unknown>" return fmt.Sprintf("<unknown:%d>", k)
} }
} }