diff --git a/serialization/timeuuid/marshal_utils.go b/serialization/timeuuid/marshal_utils.go index c11628df2..35d0a5806 100644 --- a/serialization/timeuuid/marshal_utils.go +++ b/serialization/timeuuid/marshal_utils.go @@ -115,6 +115,9 @@ func encReflectBytes(rv reflect.Value) ([]byte, error) { // The following code was taken from the `Parse` function of the "github.com/google/uuid" package. func encReflectString(v reflect.Value) ([]byte, error) { s := v.String() + if s == zeroUUID { + return make([]byte, 0), nil + } switch len(s) { case 45: // urn:timeuuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx if !strings.EqualFold(s[:9], "urn:timeuuid:") { @@ -165,6 +168,9 @@ func encReflectString(v reflect.Value) ([]byte, error) { // encString encodes uuid strings. // The following code was taken from the `Parse` function of the "github.com/google/uuid" package. func encString(s string) ([]byte, error) { + if s == zeroUUID { + return make([]byte, 0), nil + } switch len(s) { case 45: // urn:timeuuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx if !strings.EqualFold(s[:9], "urn:timeuuid:") { diff --git a/serialization/timeuuid/unmarshal_utils.go b/serialization/timeuuid/unmarshal_utils.go index f9a094a0d..d6b6ad320 100644 --- a/serialization/timeuuid/unmarshal_utils.go +++ b/serialization/timeuuid/unmarshal_utils.go @@ -6,7 +6,10 @@ import ( "time" ) -const hexString = "0123456789abcdef" +const ( + hexString = "0123456789abcdef" + zeroUUID = "00000000-0000-0000-0000-000000000000" +) var ( offsets = [...]int{0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34} @@ -104,7 +107,7 @@ func DecString(p []byte, v *string) error { if p == nil { *v = "" } else { - *v = "00000000-0000-0000-0000-000000000000" + *v = zeroUUID } case 16: *v = decString(p) @@ -123,7 +126,7 @@ func DecStringR(p []byte, v **string) error { if p == nil { *v = nil } else { - tmp := "00000000-0000-0000-0000-000000000000" + tmp := zeroUUID *v = &tmp } case 16: @@ -255,7 +258,7 @@ func decReflectString(p []byte, v reflect.Value) error { if p == nil { v.SetString("") } else { - v.SetString("00000000-0000-0000-0000-000000000000") + v.SetString(zeroUUID) } case 16: v.SetString(decString(p)) @@ -313,7 +316,7 @@ func decReflectStringR(p []byte, v reflect.Value) error { v.Set(reflect.Zero(v.Type())) } else { val := reflect.New(v.Type().Elem()) - val.Elem().SetString("00000000-0000-0000-0000-000000000000") + val.Elem().SetString(zeroUUID) v.Set(val) } case 16: