Skip to content

Conversation

hymerman
Copy link
Contributor

@hymerman hymerman commented Jan 19, 2017

This is something I did a long time ago, to make date serialization faster and take less space once serialized.

It's not pretty code but it works - I'll leave it up to you to decide if it can be merged or not, or if it needs rework!

Edit: re-pushed with new formatting and tests namespace.

if (instance is DateTimeOffset) {
var dateTimeOffset = (DateTimeOffset)instance;
serialized = new fsData(dateTimeOffset.ToString(DateTimeOffsetFormatString));
serialized = new fsData(dateTimeOffset.Ticks);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intentional? The fsConfig comment implies that this should still be serialized as a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I honestly can't remember - I wrote this ages ago and forgot to submit a PR... it looks like I thought I had a reason for sticking to string for DateTimeOffset. Maybe this code is just a left-over experiment? I'll have a look.

if (instance is DateTime) {
var dateTime = (DateTime)instance;
serialized = new fsData(dateTime.ToString(DateTimeFormatString));
if(Serializer.Config.SerializeDateTimeAsInteger) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if (

serialized = new fsData(dateTime.Ticks);
} else {
serialized = new fsData(dateTime.ToString(DateTimeFormatString));
return fsResult.Success;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop return (handled immediately below)

if (instance is TimeSpan) {
var timeSpan = (TimeSpan)instance;
serialized = new fsData(timeSpan.ToString());
if(Serializer.Config.SerializeDateTimeAsInteger) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if (

}

public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
if (data.IsString == false) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop all of the config checks in this function; deserialization should be successful regardless of the current config mode.

@hymerman hymerman force-pushed the dates-as-integers branch from 0cbe3cb to 536311d Compare July 4, 2017 15:07
@jacobdufault
Copy link
Owner

This PR seems to behavior changes even if a config flag is not swapped so I'll leave it open w/o merging for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants