goprotobuf: Use encoding.TextMarshaler and encoding.TextUnmarshaler in place of
the identical custom interfaces.
encoding.Text{Marshaler,Unmarshaler} were added in Go 1.2 (April 2013);
it's safe to rely on them now.
LGTM=r
R=r
CC=golang-codereviews
https://codereview.appspot.com/181770043
diff --git a/proto/text_parser.go b/proto/text_parser.go
index 1799e1b..dc477c9 100644
--- a/proto/text_parser.go
+++ b/proto/text_parser.go
@@ -35,6 +35,7 @@
// TODO: message sets.
import (
+ "encoding"
"errors"
"fmt"
"reflect"
@@ -43,13 +44,6 @@
"unicode/utf8"
)
-// textUnmarshaler is implemented by Messages that can unmarshal themsleves.
-// It is identical to encoding.TextUnmarshaler, introduced in go 1.2,
-// which will eventually replace it.
-type textUnmarshaler interface {
- UnmarshalText(text []byte) error
-}
-
type ParseError struct {
Message string
Line int // 1-based line number
@@ -659,7 +653,7 @@
default:
return p.errorf("expected '{' or '<', found %q", tok.value)
}
- // TODO: Handle nested messages which implement textUnmarshaler.
+ // TODO: Handle nested messages which implement encoding.TextUnmarshaler.
return p.readStruct(fv, terminator)
case reflect.Uint32:
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
@@ -680,7 +674,7 @@
// If a required field is not set and no other error occurs,
// UnmarshalText returns *RequiredNotSetError.
func UnmarshalText(s string, pb Message) error {
- if um, ok := pb.(textUnmarshaler); ok {
+ if um, ok := pb.(encoding.TextUnmarshaler); ok {
err := um.UnmarshalText([]byte(s))
return err
}