forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from illia-li/il/fix/marshal/uuids
Fix `uuid`, `timeuuid` marshal, unmarshall
- Loading branch information
Showing
12 changed files
with
1,410 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package timeuuid | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
func Marshal(value interface{}) ([]byte, error) { | ||
switch v := value.(type) { | ||
case nil: | ||
return nil, nil | ||
case [16]byte: | ||
return EncArray(v) | ||
case *[16]byte: | ||
return EncArrayR(v) | ||
case []byte: | ||
return EncSlice(v) | ||
case *[]byte: | ||
return EncSliceR(v) | ||
case string: | ||
return EncString(v) | ||
case *string: | ||
return EncStringR(v) | ||
default: | ||
// Custom types (type MyUUID [16]byte) can be serialized only via `reflect` package. | ||
// Later, when generic-based serialization is introduced we can do that via generics. | ||
rv := reflect.ValueOf(value) | ||
if rv.Kind() != reflect.Ptr { | ||
return EncReflect(rv) | ||
} | ||
return EncReflectR(rv) | ||
} | ||
} |
Oops, something went wrong.