new PropertyDescriptor(lenField, clazz); Method readMethod = len_field_pd.getReadMethod(); Integer integer = Integer.valueOf(readMethod.invoke(this).toString()); if (type == String.class) { CharSequence charSequence = byteBuf.readCharSequence(integer, CharsetUtil.UTF_8); writeMethod.invoke(this, charSequence); } else { byte[] bytes = new byte[integer]; byteBuf.readBytes(bytes); writeMethod.invoke(this, bytes); } } else { throw new RuntimeException(fieldName + " 没有@ProtocolField注解!!"); } //对于BaseBodyCodec[]类型的 如果没有指定名长度则 一定是要放在最后 因为后面只能根据判断后面是否还存在可读字节 //来处理是否继续读取 一直循环下去 if (type.isArray() && type.getComponentType().getSuperclass() == BaseBodyCodec.class) { Class componentType = type.getComponentType(); if (field.isAnnotationPresent(ProtocolField.class)) { int itemLen = 0; ProtocolField pf = field.getAnnotation(ProtocolField.class); int len = pf.len(); String lenField = pf.lenField(); if (len != -1) { itemLen = len; } else if (!lenField.equals("")) { PropertyDescriptor len_field_pd = new PropertyDescriptor(lenField, clazz); Method readMethod = len_field_pd.getReadMethod(); itemLen = Integer.valueOf(readMethod.invoke(this).toString()); } Object o = Array.newInstance(componentType, itemLen); for (int j = 0; j < itemLen; j++) { BaseBodyCodec item_o = (BaseBodyCodec) componentType.newInstance(); byteBuf.retain(); item_o.fillBodyPojo(byteBuf); Array.set(o, j, item_o); } writeMethod.invoke(this, o); } else { //判断是不是最后一项 if (i == declaredFields.length - 1) { ArrayList tmpList = new ArrayList(); while (byteBuf.isReadable()) { BaseBodyCodec item_o = (BaseBodyCodec) componentType.newInstance(); byteBuf.retain(); item_o.fillBodyPoko(byteBuf); tmpList.add(item_o); } Object[] objects = tmpList.toArray(); Object o = Array.newInstance(componentType, objects.length); for (int j = 0; j < objects.length; j++) { Array.set(o, j, objects[j]); } writeMethod.invoke(this, o); } else { throw new RuntimeException(fieldName + " 没有注解而且不是最后一项无法正常解析!!"); } } if (type.getSuperclass() == BaseBodyCodec.class) {
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Комментарии ( 0 )