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

feat: new xlang spec impl #1690

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/specification/xlang_serialization_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ Note:

- Unsigned int/long are not added here, since not every language support those types.

### Polymorphisms

For polymorphism, if one non-final class is registered, and only one subclass is registered, then we can take all
elements in List/Map have same type, thus reduce runtime check cost.

### Type disambiguation

Due to differences between type systems of languages, those types can't be mapped one-to-one between languages. When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ public void register(Class<?> cls, boolean createSerializer) {
}

@Override
public void register(Class<?> cls, Short id) {
public void register(Class<?> cls, int id) {
registerCallback(fury -> fury.register(cls, id));
}

@Override
public void register(Class<?> cls, Short id, boolean createSerializer) {
public void register(Class<?> cls, int id, boolean createSerializer) {
registerCallback(fury -> fury.register(cls, id, createSerializer));
}

@Override
public void register(Class<?> cls, String typeName) {
registerCallback(fury -> fury.register(cls, typeName));
}

@Override
public void register(Class<?> cls, String namespace, String typeName) {
registerCallback(fury -> fury.register(cls, namespace, typeName));
}

@Override
public <T> void registerSerializer(Class<T> type, Class<? extends Serializer> serializerClass) {
registerCallback(fury -> fury.registerSerializer(type, serializerClass));
Expand Down
39 changes: 31 additions & 8 deletions java/fury-core/src/main/java/org/apache/fury/BaseFury.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,28 @@
public interface BaseFury {

/**
* register class.
* Register class and allocate an auto-grown ID for this class. Note that the registration order
* is important. If registration order is inconsistent, the allocated ID will be different, and
* the deserialization will failed.
*
* @param cls class to register.
*/
void register(Class<?> cls);

/** register class with given id. */
void register(Class<?> cls, int id);

/**
* Register class.
* Register class and allocate an auto-grown ID for this class. Note that the registration order
* is important. If registration order is inconsistent, the allocated ID will be different, and
* the deserialization will failed.
*
* @param cls class to register.
* @param createSerializer whether to create serializer, if true and codegen enabled, this will
* generate the serializer code too.
*/
void register(Class<?> cls, boolean createSerializer);

/** register class with given id. */
void register(Class<?> cls, Short id);

/**
* Register class with specified id.
*
Expand All @@ -59,21 +63,40 @@ public interface BaseFury {
* @param createSerializer whether to create serializer, if true and codegen enabled, this will
* generate the serializer code too.
*/
void register(Class<?> cls, Short id, boolean createSerializer);
void register(Class<?> cls, int id, boolean createSerializer);

/** register class with given type name which will be used for cross-language serialization. */
void register(Class<?> cls, String typeName);

/**
* register class with given type namespace and name which will be used for cross-language
* serialization.
*/
void register(Class<?> cls, String namespace, String typeName);

/**
* Register a Serializer.
* Register a Serializer for a class, and allocate an auto-grown ID for this class if it's not
* registered yet. Note that the registration order is important. If registration order is
* inconsistent, the allocated ID will be different, and the deserialization will failed.
*
* @param type class needed to be serialized/deserialized.
* @param serializerClass serializer class can be created with {@link Serializers#newSerializer}.
* @param <T> type of class.
*/
<T> void registerSerializer(Class<T> type, Class<? extends Serializer> serializerClass);

/**
* Register a Serializer for a class, and allocate an auto-grown ID for this class if it's not
* registered yet. Note that the registration order is important. If registration order is
* inconsistent, the allocated ID will be different, and the deserialization will failed.
*/
void registerSerializer(Class<?> type, Serializer<?> serializer);

/**
* Register a Serializer created by serializerCreator when fury created.
* Register a Serializer created by serializerCreator when fury created. And allocate an
* auto-grown ID for this class if it's not registered yet. Note that the registration order is
* important. If registration order is inconsistent, the allocated ID will be different, and the
* deserialization will failed.
*
* @param type class needed to be serialized/deserialized.
* @param serializerCreator serializer creator with param {@link Fury}
Expand Down
Loading
Loading