Skip to content

Commit 30ba397

Browse files
committed
重构remotingcommand协议解析部分。
1 parent 5ad1b2d commit 30ba397

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

rocketmq-remoting/src/main/java/com/alibaba/rocketmq/remoting/protocol/RemotingCommand.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ public void writeCustomHeader(CommandCustomHeader customHeader) {
174174
this.customHeader = customHeader;
175175
}
176176

177+
private static final String StringName = String.class.getCanonicalName();//
178+
179+
private static final String IntegerName1 = Integer.class.getCanonicalName();//
180+
private static final String IntegerName2 = int.class.getCanonicalName();//
181+
182+
private static final String LongName1 = Long.class.getCanonicalName();//
183+
private static final String LongName2 = long.class.getCanonicalName();//
184+
185+
private static final String BooleanName1 = Boolean.class.getCanonicalName();//
186+
private static final String BooleanName2 = boolean.class.getCanonicalName();//
187+
188+
private static final String DoubleName1 = Double.class.getCanonicalName();//
189+
private static final String DoubleName2 = double.class.getCanonicalName();//
190+
177191

178192
public CommandCustomHeader decodeCommandCustomHeader(Class<? extends CommandCustomHeader> classHeader)
179193
throws RemotingCommandException {
@@ -203,37 +217,27 @@ public CommandCustomHeader decodeCommandCustomHeader(Class<? extends CommandCust
203217
throw new RemotingCommandException("the custom field <" + fieldName
204218
+ "> is null");
205219
}
220+
221+
continue;
206222
}
207223

208224
field.setAccessible(true);
209-
String type = field.getType().getSimpleName();
225+
String type = field.getType().getCanonicalName();
210226
Object valueParsed = null;
211227

212-
if (type.equals("String")) {
228+
if (type.equals(StringName)) {
213229
valueParsed = value;
214230
}
215-
else if (type.equals("Integer")) {
216-
valueParsed = Integer.parseInt(value);
217-
}
218-
else if (type.equals("Long")) {
219-
valueParsed = Long.parseLong(value);
220-
}
221-
else if (type.equals("Boolean")) {
222-
valueParsed = Boolean.parseBoolean(value);
223-
}
224-
else if (type.equals("Double")) {
225-
valueParsed = Double.parseDouble(value);
226-
}
227-
else if (type.equals("int")) {
231+
else if (type.equals(IntegerName1) || type.equals(IntegerName2)) {
228232
valueParsed = Integer.parseInt(value);
229233
}
230-
else if (type.equals("long")) {
234+
else if (type.equals(LongName1) || type.equals(LongName2)) {
231235
valueParsed = Long.parseLong(value);
232236
}
233-
else if (type.equals("boolean")) {
237+
else if (type.equals(BooleanName1) || type.equals(BooleanName2)) {
234238
valueParsed = Boolean.parseBoolean(value);
235239
}
236-
else if (type.equals("double")) {
240+
else if (type.equals(DoubleName1) || type.equals(DoubleName2)) {
237241
valueParsed = Double.parseDouble(value);
238242
}
239243
else {

0 commit comments

Comments
 (0)