Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to save DateTime and TimeOffset as Int64 #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

return fsResult.Success;
}

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.

@@ -27,31 +27,45 @@ public class fsDateConverter : fsConverter {
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
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)

return fsResult.Success;
}

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 (

return fsResult.Success;
}

throw new InvalidOperationException("FullSerializer Internal Error -- Unexpected serialization type");
}

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