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 #374 from illia-li/il/fix/marshal/date
Fix `date` marshal, unmarshall functions
- Loading branch information
Showing
8 changed files
with
881 additions
and
327 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,42 @@ | ||
package date | ||
|
||
import ( | ||
"reflect" | ||
"time" | ||
) | ||
|
||
func Marshal(value interface{}) ([]byte, error) { | ||
switch v := value.(type) { | ||
case nil: | ||
return nil, nil | ||
case int32: | ||
return EncInt32(v) | ||
case int64: | ||
return EncInt64(v) | ||
case uint32: | ||
return EncUint32(v) | ||
case string: | ||
return EncString(v) | ||
case time.Time: | ||
return EncTime(v) | ||
|
||
case *int32: | ||
return EncInt32R(v) | ||
case *int64: | ||
return EncInt64R(v) | ||
case *uint32: | ||
return EncUint32R(v) | ||
case *string: | ||
return EncStringR(v) | ||
case *time.Time: | ||
return EncTimeR(v) | ||
default: | ||
// Custom types (type MyDate uint32) can be serialized only via `reflect` package. | ||
// Later, when generic-based serialization is introduced we can do that via generics. | ||
rv := reflect.TypeOf(value) | ||
if rv.Kind() != reflect.Ptr { | ||
return EncReflect(reflect.ValueOf(v)) | ||
} | ||
return EncReflectR(reflect.ValueOf(v)) | ||
} | ||
} |
Oops, something went wrong.