瀏覽代碼

Merge pull request #502 from ChannelMeter/fix/panic-on-nil-udt-field

Encode the UDT field as null if the struct value is nil. Fixes #501.
Chris Bannister 10 年之前
父節點
當前提交
7265a91e3b
共有 1 個文件被更改,包括 10 次插入1 次删除
  1. 10 1
      marshal.go

+ 10 - 1
marshal.go

@@ -1356,7 +1356,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())