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

chore(java): rename EnumString to MetaString #1516

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix missing meta string rename
  • Loading branch information
chaokunyang committed Apr 15, 2024
commit 1b8cd2cf416a88470cc1d18a5fa02c75dba37db0
12 changes: 6 additions & 6 deletions go/fury/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,17 @@ func (r *typeResolver) writeType(buffer *ByteBuffer, type_ reflect.Type) error {
}

func (r *typeResolver) readType(buffer *ByteBuffer) (reflect.Type, error) {
enumString, err := r.readMetaString(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 @@ -527,11 +527,11 @@ func (r *typeResolver) writeTypeTag(buffer *ByteBuffer, typeTag string) error {
}

func (r *typeResolver) readTypeByReadTag(buffer *ByteBuffer) (reflect.Type, error) {
enumString, err := r.readMetaString(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public final class MetaStringResolver {
private static final float furyMapLoadFactor = 0.25f;

// Every deserialization for unregistered string will query it, performance is important.
private final ObjectMap<MetaStringBytes, String> enumStringBytes2StringMap =
private final ObjectMap<MetaStringBytes, String> metaStringBytes2StringMap =
new ObjectMap<>(initialCapacity, furyMapLoadFactor);
private final LongMap<MetaStringBytes> hash2MetaStringBytesMap =
new LongMap<>(initialCapacity, furyMapLoadFactor);
// Every enum bytes should be singleton at every fury, since we keep state in it.
private final ObjectMap<String, MetaStringBytes> enumString2BytesMap =
private final ObjectMap<String, MetaStringBytes> metaString2BytesMap =
new ObjectMap<>(initialCapacity, furyMapLoadFactor);
private MetaStringBytes[] dynamicWrittenString = new MetaStringBytes[32];
private MetaStringBytes[] dynamicReadStringIds = new MetaStringBytes[32];
Expand All @@ -56,10 +56,10 @@ public MetaStringResolver() {
}

MetaStringBytes getOrCreateMetaStringBytes(String str) {
MetaStringBytes metaStringBytes = enumString2BytesMap.get(str);
MetaStringBytes metaStringBytes = metaString2BytesMap.get(str);
if (metaStringBytes == null) {
metaStringBytes = new MetaStringBytes(str);
enumString2BytesMap.put(str, metaStringBytes);
metaString2BytesMap.put(str, metaStringBytes);
}
return metaStringBytes;
}
Expand All @@ -70,10 +70,10 @@ public void writeMetaString(MemoryBuffer buffer, String str) {

public String readMetaString(MemoryBuffer buffer) {
MetaStringBytes byteString = readMetaStringBytes(buffer);
String str = enumStringBytes2StringMap.get(byteString);
String str = metaStringBytes2StringMap.get(byteString);
if (str == null) { // TODO use org.apache.fury.resolver.ObjectMap
str = new String(byteString.bytes, StandardCharsets.UTF_8);
enumStringBytes2StringMap.put(byteString, str);
metaStringBytes2StringMap.put(byteString, str);
}
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void testWriteMetaString() {
stringResolver.writeMetaString(buffer, str);
}
for (int i = 0; i < 128; i++) {
String enumString = stringResolver.readMetaString(buffer);
assertEquals(enumString.hashCode(), str.hashCode());
assertEquals(enumString.getBytes(), str.getBytes());
String metaString = stringResolver.readMetaString(buffer);
assertEquals(metaString.hashCode(), str.hashCode());
assertEquals(metaString.getBytes(), str.getBytes());
}
assertTrue(buffer.writerIndex() < str.getBytes().length + 128 * 4);
}
Expand Down
Loading