Add comment on binary/reflect and nil-dogs

This commit is contained in:
Jae Kwon 2015-07-20 11:21:24 -07:00
parent c30d38270c
commit 6dafd68873
1 changed files with 6 additions and 0 deletions

View File

@ -447,6 +447,9 @@ func writeReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, w io.Wr
rv, rt = rv.Elem(), rt.Elem()
typeInfo = GetTypeInfo(rt)
if !rv.IsValid() {
// For better compatibility with other languages,
// as far as tendermint/binary is concerned,
// pointers to nil values are the same as nil.
WriteByte(0x00, w, n, err)
return
}
@ -845,6 +848,9 @@ func writeReflectJSON(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64,
rv, rt = rv.Elem(), rt.Elem()
typeInfo = GetTypeInfo(rt)
if !rv.IsValid() {
// For better compatibility with other languages,
// as far as tendermint/binary is concerned,
// pointers to nil values are the same as nil.
WriteTo([]byte("null"), w, n, err)
return
}