Skip to content
Merged
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
23 changes: 23 additions & 0 deletions java/fury-core/src/main/java/io/fury/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.fury;

import io.fury.type.Type;
import io.fury.util.LoggerFactory;
import javax.annotation.concurrent.NotThreadSafe;
import org.slf4j.Logger;
Expand Down Expand Up @@ -45,4 +46,26 @@ public final class Fury {
public static final byte NOT_NULL_VALUE_FLAG = -1;
// this flag indicates that the object is a referencable and first read.
public static final byte REF_VALUE_FLAG = 0;
public static final byte NOT_SUPPORT_CROSS_LANGUAGE = 0;
public static final short FURY_TYPE_TAG_ID = Type.FURY_TYPE_TAG.getId();

private final boolean referenceTracking;
private final Language language;

public Fury() {
referenceTracking = false;
language = null;
}

public Language getLanguage() {
return language;
}

public boolean trackingReference() {
return referenceTracking;
}

public boolean isBasicTypesReferenceIgnored() {
return false;
}
}
32 changes: 32 additions & 0 deletions java/fury-core/src/main/java/io/fury/Language.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023 The Fury authors
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.fury;

/**
* Language supported by fury.
*
* @author chaokunyang
*/
public enum Language {
XLANG,
JAVA,
PYTHON,
CPP,
GO,
}
101 changes: 101 additions & 0 deletions java/fury-core/src/main/java/io/fury/serializer/Serializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2023 The Fury authors
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.fury.serializer;

import com.google.common.primitives.Primitives;
import io.fury.Fury;
import io.fury.Language;
import io.fury.memory.MemoryBuffer;
import javax.annotation.concurrent.NotThreadSafe;

/**
* Serialize/deserializer objects into binary. Note that this class is designed as an abstract class
* instead of interface to reduce virtual method call cost of {@link #needToWriteReference}/{@link
* #getCrossLanguageTypeId}.
*
* @param <T> type of objects being serializing/deserializing
* @author chaokunyang
*/
@NotThreadSafe
public abstract class Serializer<T> {
protected final Fury fury;
protected final Class<T> type;
protected final boolean isJava;
protected final boolean needToWriteReference;

public void write(MemoryBuffer buffer, T value) {
throw new UnsupportedOperationException();
}

public T read(MemoryBuffer buffer) {
throw new UnsupportedOperationException();
}

/**
* Returns {@link Fury#NOT_SUPPORT_CROSS_LANGUAGE} if the serializer doesn't support
* cross-language serialization. Return a number in range (0, 32767) if the serializer support
* cross-language serialization and native serialization data is the same with cross-language
* serialization. Return a negative short in range [-32768, 0) if the serializer support
* cross-language serialization and native serialization data is not the same with cross-language
* serialization.
*/
public short getCrossLanguageTypeId() {
return Fury.NOT_SUPPORT_CROSS_LANGUAGE;
}

/** Returns a type tag used for setup type mapping between languages. */
public String getCrossLanguageTypeTag() {
throw new UnsupportedOperationException();
}

public void crossLanguageWrite(MemoryBuffer buffer, T value) {
throw new UnsupportedOperationException();
}

public T crossLanguageRead(MemoryBuffer buffer) {
throw new UnsupportedOperationException();
}

public Serializer(Fury fury, Class<T> type) {
this.fury = fury;
this.type = type;
this.isJava = fury.getLanguage() == Language.JAVA;
if (fury.trackingReference()) {
needToWriteReference =
!Primitives.isWrapperType(Primitives.wrap(type)) || !fury.isBasicTypesReferenceIgnored();
} else {
needToWriteReference = false;
}
}

public Serializer(Fury fury, Class<T> type, boolean needToWriteReference) {
this.fury = fury;
this.type = type;
this.isJava = fury.getLanguage() == Language.JAVA;
this.needToWriteReference = needToWriteReference;
}

public final boolean needToWriteReference() {
return needToWriteReference;
}

public Class<T> getType() {
return type;
}
}