Skip to content

Commit

Permalink
perf[protocol]: fix string default value
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Sep 27, 2023
1 parent d969856 commit 456fc9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions protocol/src/main/java/com/zfoo/protocol/ProtocolManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static void write(ByteBuf buffer, Object packet) {

/**
* deserialization a packet from the buffer
* <p>
* byte[] convert to ByteBuf using Unpooled.wrappedBuffer(byte[]) in netty
* ByteBuf convert to byte[] using ByteBufUtils.readAllBytes(ByteBuf) in zfoo
*/
public static Object read(ByteBuf buffer) {
return protocols[ByteBufUtils.readShort(buffer)].read(buffer);
Expand All @@ -81,6 +84,7 @@ public static IProtocolRegistration getProtocol(Class<?> protocolClass) {
public static ProtocolModule moduleByProtocolId(short id) {
return modules[protocols[id].module()];
}

public static ProtocolModule moduleByProtocol(Class<?> clazz) {
return moduleByProtocolId(protocolId(clazz));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
@Override
public String defaultValue(StringBuilder builder, Field field, IFieldRegistration fieldRegistration) {
var result = "result" + GenerateProtocolFile.index.getAndIncrement();
builder.append(StringUtils.format("String {} = \"\"", result));
builder.append(StringUtils.format("String {} = \"\";", result));
return result;
}

Expand Down

0 comments on commit 456fc9c

Please sign in to comment.