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 an externalizable serializer that uses ObjectInput and ObjectOutput ... #167

Merged
merged 6 commits into from
Mar 22, 2014

Conversation

rdifalco
Copy link
Contributor

@rdifalco rdifalco commented Jan 7, 2014

...adapters but has the ability to switch when fancy serialization stuff is tried.

I'm not super familiar with this library so I hope I kept the right code philosophy. The ability to branch to the JavaSerializer is disabled by default. But I added test cases to ensure it worked and properly did a readResolve.

…ut adapters but has the ability to switch when fancy serialization stuff is tried.
int total = 0;
int cur = 0;

while ((total<n) && ((cur = (int) input.skip( (long)n-total) ) > 0)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think Input#skip should be sufficient without the while loop.

Robert DiFalco and others added 2 commits January 7, 2014 15:43
@rdifalco
Copy link
Contributor Author

rdifalco commented Jan 7, 2014

Alright, I think I fielded all the comments. Let me know if I've missed anything.

/**
* Copyright (c) 2012,2013
*/
public class ExternalizableMaySerializeSerializer extends ExternalizableSerializer {
Copy link
Member

Choose a reason for hiding this comment

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

This class name is not great. Why not have ExternalizableSerializer be able to fall back to JavaSerializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason for having two versions was to prevent from having to keep
a bunch of classes in memory and mapped to JavaSerializers as well as the
suppress "replace method" check option. Two classes seemed to be much more
memory conscious and performant. But yeah, I hear you on the name.

On Fri, Jan 10, 2014 at 10:45 AM, Nathan Sweet [email protected]:

In
src/com/esotericsoftware/kryo/serializers/ExternalizableMaySerializeSerializer.java:

@@ -0,0 +1,67 @@
+package com.esotericsoftware.kryo.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import java.lang.reflect.Method;
+
+/**

  • * Copyright (c) 2012,2013
  • */
    +public class ExternalizableMaySerializeSerializer extends ExternalizableSerializer {

This class name is not great. Why not have ExternalizableSerializer be
able to fall back to JavaSerializer?


Reply to this email directly or view it on GitHubhttps://pull/167/files#r8797792
.

Copy link
Member

Choose a reason for hiding this comment

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

The name is a no-go. There doesn't seem to be a map anymore, can the classes be combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so what I'm thinking here is that the option to NOT fall-back on JavaSerialization is an unnecessary optimization. The simplest thing that could work here is to just make the fall back always checked, push this implementation into ExternalizableSerializer and just get rid of this class. Work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, just so I'm crystal clear.

  1. A single serializer does not need to be thread safe.
  2. A single serializer CAN be used on different classes. (Hence the need for a map)

Is that correct?

@mucaho
Copy link

mucaho commented Feb 20, 2014

I too needed Kryo to implement ObjectInput / ObjectOutput, so I welcome this PR.

readFully( b, 0, b.length );
}

public void readFully( byte[] b, int off, int len ) throws IOException {
Copy link

Choose a reason for hiding this comment

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

why not use Input.readBytes(byte[], int, int) here? catch KryoException and convert to appropriate IOException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed like this would be both optimal and more proper if someone ever decided to implement an Input that used a socket or some such. I can change it to just call readBytes if you think it's an important improvement. I wasn't really sure what the difference is so I went for a stock readFully implementation.

Copy link
Member

Choose a reason for hiding this comment

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

I believe readBytes should do the same as readyFully.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed.

@NathanSweet
Copy link
Member

If we can address the comments above and run the source formatter, then we can merge.

@rdifalco
Copy link
Contributor Author

Can you point me to the source code formatter?

On Fri, Mar 21, 2014 at 8:34 AM, Nathan Sweet [email protected]:

If we can address the comments above and run the source formatter, then we
can merge.

Reply to this email directly or view it on GitHubhttps://pull/167#issuecomment-38287933
.

@mucaho
Copy link

mucaho commented Mar 21, 2014

nathansweet is mentioned by name in libgdx's wiki section on formatting. I think thats the one

@rdifalco
Copy link
Contributor Author

Good enough. Using the code format settings from that project.

On Fri, Mar 21, 2014 at 9:56 AM, mucaho [email protected] wrote:

nathansweet is mentioned by name in libgdx's wiki section on formattinghttps:/libgdx/libgdx/wiki/Contributing#eclipse-formatter.
I think thats the one

Reply to this email directly or view it on GitHubhttps://pull/167#issuecomment-38297579
.

@NathanSweet
Copy link
Member

The formatter settings are committed in the .settings Eclipse folder in the Kryo project. Source -> Format should run it using project specific settings. It looks slightly out of date since the comments weren't formatted quite right, but close enough.

NathanSweet added a commit that referenced this pull request Mar 22, 2014
Add an externalizable serializer that uses ObjectInput and ObjectOutput ...
@NathanSweet NathanSweet merged commit c2c75cc into EsotericSoftware:master Mar 22, 2014
@mucaho mucaho mentioned this pull request Sep 13, 2014
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants