Skip to content

Commit

Permalink
chore(java): rename EnumString to MetaString (apache#1516)
Browse files Browse the repository at this point in the history
## What does this PR do?

This PR renames EnumString to MetaString

## Related issues
apache#1514 


## Does this PR introduce any user-facing change?

<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/incubator-fury/issues/new/choose)
describing the need to do so and update the document if necessary.
-->

- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?


## Benchmark

<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
  • Loading branch information
chaokunyang authored Apr 15, 2024
1 parent 8f79cb0 commit 4fabf69
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 146 deletions.
22 changes: 11 additions & 11 deletions go/fury/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,25 +403,25 @@ func (r *typeResolver) writeType(buffer *ByteBuffer, type_ reflect.Type) error {
r.typeToTypeInfo[type_] = encodeType
}
}
if err := r.writeEnumString(buffer, typeInfo); err != nil {
if err := r.writeMetaString(buffer, typeInfo); err != nil {
return err
} else {
return nil
}
}

func (r *typeResolver) readType(buffer *ByteBuffer) (reflect.Type, error) {
enumString, err := r.readEnumString(buffer)
metaString, err := r.readMetaString(buffer)
if err != nil {
return nil, err
}
type_, ok := r.typeInfoToType[enumString]
type_, ok := r.typeInfoToType[metaString]
if !ok {
type_, _, err = r.decodeType(enumString)
type_, _, err = r.decodeType(metaString)
if err != nil {
return nil, err
} else {
r.typeInfoToType[enumString] = type_
r.typeInfoToType[metaString] = type_
}
}
return type_, nil
Expand Down Expand Up @@ -519,23 +519,23 @@ func (r *typeResolver) decodeType(typeStr string) (reflect.Type, string, error)
}

func (r *typeResolver) writeTypeTag(buffer *ByteBuffer, typeTag string) error {
if err := r.writeEnumString(buffer, typeTag); err != nil {
if err := r.writeMetaString(buffer, typeTag); err != nil {
return err
} else {
return nil
}
}

func (r *typeResolver) readTypeByReadTag(buffer *ByteBuffer) (reflect.Type, error) {
enumString, err := r.readEnumString(buffer)
metaString, err := r.readMetaString(buffer)
if err != nil {
return nil, err
}
return r.typeTagToSerializers[enumString].(*ptrToStructSerializer).type_, err
return r.typeTagToSerializers[metaString].(*ptrToStructSerializer).type_, err
}

func (r *typeResolver) readTypeInfo(buffer *ByteBuffer) (string, error) {
return r.readEnumString(buffer)
return r.readMetaString(buffer)
}

func (r *typeResolver) getTypeById(id int16) (reflect.Type, error) {
Expand All @@ -546,7 +546,7 @@ func (r *typeResolver) getTypeById(id int16) (reflect.Type, error) {
return type_, nil
}

func (r *typeResolver) writeEnumString(buffer *ByteBuffer, str string) error {
func (r *typeResolver) writeMetaString(buffer *ByteBuffer, str string) error {
if id, ok := r.dynamicStringToId[str]; !ok {
dynamicStringId := r.dynamicStringId
r.dynamicStringId += 1
Expand All @@ -571,7 +571,7 @@ func (r *typeResolver) writeEnumString(buffer *ByteBuffer, str string) error {
return nil
}

func (r *typeResolver) readEnumString(buffer *ByteBuffer) (string, error) {
func (r *typeResolver) readMetaString(buffer *ByteBuffer) (string, error) {
if buffer.ReadByte_() == useStringValue {
// TODO support use computed hash
buffer.ReadInt64()
Expand Down
20 changes: 10 additions & 10 deletions java/fury-core/src/main/java/org/apache/fury/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import org.apache.fury.resolver.ClassInfo;
import org.apache.fury.resolver.ClassInfoHolder;
import org.apache.fury.resolver.ClassResolver;
import org.apache.fury.resolver.EnumStringResolver;
import org.apache.fury.resolver.MapRefResolver;
import org.apache.fury.resolver.MetaStringResolver;
import org.apache.fury.resolver.NoRefResolver;
import org.apache.fury.resolver.RefResolver;
import org.apache.fury.resolver.SerializationContext;
Expand Down Expand Up @@ -101,7 +101,7 @@ public final class Fury implements BaseFury {
private final boolean refTracking;
private final RefResolver refResolver;
private final ClassResolver classResolver;
private final EnumStringResolver enumStringResolver;
private final MetaStringResolver metaStringResolver;
private final SerializationContext serializationContext;
private final ClassLoader classLoader;
private final JITContext jitContext;
Expand Down Expand Up @@ -132,7 +132,7 @@ public Fury(FuryBuilder builder, ClassLoader classLoader) {
this.refResolver = new NoRefResolver();
}
jitContext = new JITContext(this);
enumStringResolver = new EnumStringResolver();
metaStringResolver = new MetaStringResolver();
classResolver = new ClassResolver(this);
classResolver.initialize();
serializationContext = new SerializationContext();
Expand Down Expand Up @@ -325,7 +325,7 @@ private void xserializeInternal(MemoryBuffer buffer, Object obj) {
refResolver.resetWrite();
// fury write opaque object classname which cause later write of classname only write an id.
classResolver.resetWrite();
enumStringResolver.resetWrite();
metaStringResolver.resetWrite();
for (Object nativeObject : nativeObjects) {
writeRef(buffer, nativeObject);
}
Expand Down Expand Up @@ -807,7 +807,7 @@ private Object xdeserializeInternal(MemoryBuffer buffer) {
buffer.readerIndex(readerIndex);
refResolver.resetRead();
classResolver.resetRead();
enumStringResolver.resetRead();
metaStringResolver.resetRead();
}
obj = xreadRef(buffer);
buffer.readerIndex(endReaderIndex);
Expand Down Expand Up @@ -1241,7 +1241,7 @@ private void serializeToStream(OutputStream outputStream, Consumer<MemoryBuffer>
public void reset() {
refResolver.reset();
classResolver.reset();
enumStringResolver.reset();
metaStringResolver.reset();
serializationContext.reset();
nativeObjects.clear();
peerOutOfBandEnabled = false;
Expand All @@ -1252,7 +1252,7 @@ public void reset() {
public void resetWrite() {
refResolver.resetWrite();
classResolver.resetWrite();
enumStringResolver.resetWrite();
metaStringResolver.resetWrite();
serializationContext.reset();
nativeObjects.clear();
bufferCallback = null;
Expand All @@ -1262,7 +1262,7 @@ public void resetWrite() {
public void resetRead() {
refResolver.resetRead();
classResolver.resetRead();
enumStringResolver.resetRead();
metaStringResolver.resetRead();
serializationContext.reset();
nativeObjects.clear();
peerOutOfBandEnabled = false;
Expand Down Expand Up @@ -1305,8 +1305,8 @@ public ClassResolver getClassResolver() {
return classResolver;
}

public EnumStringResolver getEnumStringResolver() {
return enumStringResolver;
public MetaStringResolver getMetaStringResolver() {
return metaStringResolver;
}

public SerializationContext getSerializationContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@
*/
public class ClassInfo {
final Class<?> cls;
final EnumStringBytes fullClassNameBytes;
final EnumStringBytes packageNameBytes;
final EnumStringBytes classNameBytes;
final MetaStringBytes fullClassNameBytes;
final MetaStringBytes packageNameBytes;
final MetaStringBytes classNameBytes;
final boolean isDynamicGeneratedClass;
final EnumStringBytes typeTagBytes;
final MetaStringBytes typeTagBytes;
Serializer<?> serializer;
// use primitive to avoid boxing
// class id must be less than Integer.MAX_VALUE/2 since we use bit 0 as class id flag.
short classId;

ClassInfo(
Class<?> cls,
EnumStringBytes fullClassNameBytes,
EnumStringBytes packageNameBytes,
EnumStringBytes classNameBytes,
MetaStringBytes fullClassNameBytes,
MetaStringBytes packageNameBytes,
MetaStringBytes classNameBytes,
boolean isDynamicGeneratedClass,
EnumStringBytes typeTagBytes,
MetaStringBytes typeTagBytes,
Serializer<?> serializer,
short classId) {
this.cls = cls;
Expand All @@ -71,26 +71,26 @@ public class ClassInfo {
short classId) {
this.cls = cls;
this.serializer = serializer;
EnumStringResolver enumStringResolver = classResolver.getEnumStringResolver();
MetaStringResolver metaStringResolver = classResolver.getMetaStringResolver();
if (cls != null && classResolver.getFury().getLanguage() != Language.JAVA) {
this.fullClassNameBytes = enumStringResolver.getOrCreateEnumStringBytes(cls.getName());
this.fullClassNameBytes = metaStringResolver.getOrCreateMetaStringBytes(cls.getName());
} else {
this.fullClassNameBytes = null;
}
if (cls != null
&& (classId == ClassResolver.NO_CLASS_ID || classId == ClassResolver.REPLACE_STUB_ID)) {
// REPLACE_STUB_ID for write replace class in `ClassSerializer`.
String packageName = ReflectionUtils.getPackage(cls);
this.packageNameBytes = enumStringResolver.getOrCreateEnumStringBytes(packageName);
this.packageNameBytes = metaStringResolver.getOrCreateMetaStringBytes(packageName);
this.classNameBytes =
enumStringResolver.getOrCreateEnumStringBytes(
metaStringResolver.getOrCreateMetaStringBytes(
ReflectionUtils.getClassNameWithoutPackage(cls));
} else {
this.packageNameBytes = null;
this.classNameBytes = null;
}
if (tag != null) {
this.typeTagBytes = enumStringResolver.getOrCreateEnumStringBytes(tag);
this.typeTagBytes = metaStringResolver.getOrCreateMetaStringBytes(tag);
} else {
this.typeTagBytes = null;
}
Expand Down Expand Up @@ -118,11 +118,11 @@ public short getClassId() {
return classId;
}

public EnumStringBytes getPackageNameBytes() {
public MetaStringBytes getPackageNameBytes() {
return packageNameBytes;
}

public EnumStringBytes getClassNameBytes() {
public MetaStringBytes getClassNameBytes() {
return classNameBytes;
}

Expand Down
Loading

0 comments on commit 4fabf69

Please sign in to comment.