@Override public void write(WriteBuffer buff, Object obj) { if (!isArray(obj)) { super.write(buff, obj); return; } Class<?> type = obj.getClass().getComponentType(); Integer classId = getCommonClassId(type); if (classId != null) { if (type.isPrimitive()) { if (type == byte.class) { byte[] data = (byte[]) obj; int len = data.length; if (len <= 15) { buff.put((byte) (TAG_BYTE_ARRAY_0_15 + len)); } else { buff.put((byte) TYPE_ARRAY).put((byte) classId.intValue()).putVarInt(len); } buff.put(data); return; } int len = Array.getLength(obj); buff.put((byte) TYPE_ARRAY).put((byte) classId.intValue()).putVarInt(len); for (int i = 0; i < len; i++) { if (type == boolean.class) { buff.put((byte) (((boolean[]) obj)[i] ? 1 : 0)); } else if (type == char.class) { buff.putChar(((char[]) obj)[i]); } else if (type == short.class) { buff.putShort(((short[]) obj)[i]); } else if (type == int.class) { buff.putInt(((int[]) obj)[i]); } else if (type == float.class) { buff.putFloat(((float[]) obj)[i]); } else if (type == double.class) { buff.putDouble(((double[]) obj)[i]); } else { buff.putLong(((long[]) obj)[i]); } } return; } buff.put((byte) TYPE_ARRAY).put((byte) classId.intValue()); } else { buff.put((byte) TYPE_ARRAY).put((byte) -1); String c = type.getName(); StringDataType.INSTANCE.write(buff, c); } Object[] array = (Object[]) obj; int len = array.length; buff.putVarInt(len); for (Object x : array) { elementType.write(buff, x); } }
@Override public void write(WriteBuffer buff, Object[] obj, int len, boolean key) { for (int i = 0; i < len; i++) { write(buff, obj[i]); } }