Parcourir la source

Encode the UDT field as null if the struct value is nil. Fixes #501.

Nimi Wariboko Jr il y a 10 ans
Parent
commit
fc7fbf7e07
1 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 10 1
      marshal.go

+ 10 - 1
marshal.go

@@ -1323,7 +1323,16 @@ func marshalUDT(info TypeInfo, value interface{}) ([]byte, error) {
 		if !f.IsValid() {
 			return nil, marshalErrorf("cannot marshal %T into %s", value, info)
 		} else if f.Kind() == reflect.Ptr {
-			f = f.Elem()
+			if f.IsNil() {
+				n := -1
+				buf = append(buf, byte(n>>24),
+					byte(n>>16),
+					byte(n>>8),
+					byte(n))
+				continue
+			} else {
+				f = f.Elem()
+			}
 		}
 
 		data, err := Marshal(e.Type, f.Interface())