chaokunyang commented on code in PR #1667:
URL: https://github.com/apache/incubator-fury/pull/1667#discussion_r1623137850
##########
java/fury-core/src/main/java/org/apache/fury/resolver/ClassInfo.java:
##########
@@ -86,14 +85,19 @@ public class ClassInfo {
} else {
this.fullClassNameBytes = null;
}
+ // When `classId == ClassResolver.REPLACE_STUB_ID` was established,
+ // means only classes are serialized, not the instance. If we
+ // serialize such class only, we need to write classname bytes.
if (cls != null
- && (classId == ClassResolver.NO_CLASS_ID || classId ==
ClassResolver.REPLACE_STUB_ID)) {
+ && ((classId == ClassResolver.NO_CLASS_ID
+ && !classResolver.getFury().getConfig().isMetaShareEnabled())
+ || classId == ClassResolver.REPLACE_STUB_ID)) {
// REPLACE_STUB_ID for write replace class in `ClassSerializer`.
Tuple2<String, String> tuple2 = Encoders.encodePkgAndClass(cls);
this.packageNameBytes =
-
metaStringResolver.getOrCreateMetaStringBytes(PACKAGE_ENCODER.encode(tuple2.f0));
+
metaStringResolver.getOrCreateMetaStringBytes(Encoders.encodePackage(tuple2.f0));
this.classNameBytes =
-
metaStringResolver.getOrCreateMetaStringBytes(TYPE_NAME_ENCODER.encode(tuple2.f1));
+
metaStringResolver.getOrCreateMetaStringBytes(Encoders.encodeTypeName(tuple2.f1));
Review Comment:
> Updated.
>
> `MetaStringBytes.decode` can also reuse existing `MetaStringDecoder`
objects
You should update MetaStringBytes#decode too:
```java
public String decode(MetaStringDecoder decoder) {
int header = (int) (hashCode & 0xff);
int encodingFlags = header & 0b111;
MetaString.Encoding encoding =
MetaString.Encoding.values()[encodingFlags];
return decoder.decode(bytes, encoding);
}
```
Currently it use the whole encoding set, but `Encoders.encodePackage` only
use part of the encodings. The decode error will happen if a classname with
unicode chars occur.
Could you add a unit test to cover such cases? It should raise error in your
current change.
And the key here is that MetaStringBytes can't distinguish whether the data
is package or classname, so the decode need use the whole encoding set
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]