Sync from internal version.
- fix nil Marshaler fields
- fix text encoding of nil
R=r
CC=golang-dev
http://codereview.appspot.com/2023043
diff --git a/proto/encode.go b/proto/encode.go
index fac4b5e..9218007 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -295,6 +295,9 @@
// Can the object marshal itself?
iv := unsafe.Unreflect(p.stype, unsafe.Pointer(base+p.offset))
if m, ok := iv.(Marshaler); ok {
+ if n, ok := reflect.NewValue(iv).(nillable); ok && n.IsNil() {
+ return ErrNil
+ }
data, err := m.Marshal()
if err != nil {
return err
@@ -464,6 +467,9 @@
// Can the object marshal itself?
iv := unsafe.Unreflect(p.stype, unsafe.Pointer(&s[i]))
if m, ok := iv.(Marshaler); ok {
+ if n, ok := reflect.NewValue(iv).(nillable); ok && n.IsNil() {
+ return ErrNil
+ }
data, err := m.Marshal()
if err != nil {
return err