private void writeStringBytes( byte[] bytes, TCDataOutput output, ObjectStringSerializer serializer) { serializer.writeStringBytes(output, bytes); }
private byte[] readStringBytes(TCDataInput input, ObjectStringSerializer serializer) throws IOException { return serializer.readStringBytes(input); }
@Override public void encode(Object value, TCDataOutput output, ObjectStringSerializer serializer) { if (value == null) { // Normally Null values should have already been converted to null ObjectID, but this is not // true when there are // multiple versions of the same class in the cluster sharign data. value = ObjectID.NULL_ID; } final LiteralValues type = LiteralValues.valueFor(value); switch (type) { case ENUM: output.writeByte(TYPE_ID_ENUM); final Class<?> enumClass = ((Enum<?>) value).getDeclaringClass(); writeString(enumClass.getName(), output, serializer); writeString(((Enum<?>) value).name(), output, serializer); break; case ENUM_HOLDER: output.writeByte(TYPE_ID_ENUM_HOLDER); writeEnumInstance((EnumInstance) value, output, serializer); break; case JAVA_LANG_CLASS: output.writeByte(TYPE_ID_JAVA_LANG_CLASS); final Class<?> c = (Class<?>) value; writeString(c.getName(), output, serializer); break; case JAVA_LANG_CLASS_HOLDER: output.writeByte(TYPE_ID_JAVA_LANG_CLASS_HOLDER); writeClassInstance((ClassInstance) value, output, serializer); break; case BOOLEAN: output.writeByte(TYPE_ID_BOOLEAN); output.writeBoolean(((Boolean) value).booleanValue()); break; case BYTE: output.writeByte(TYPE_ID_BYTE); output.writeByte(((Byte) value).byteValue()); break; case CHARACTER: output.writeByte(TYPE_ID_CHAR); output.writeChar(((Character) value).charValue()); break; case DOUBLE: output.writeByte(TYPE_ID_DOUBLE); output.writeDouble(((Double) value).doubleValue()); break; case FLOAT: output.writeByte(TYPE_ID_FLOAT); output.writeFloat(((Float) value).floatValue()); break; case INTEGER: output.writeByte(TYPE_ID_INT); output.writeInt(((Integer) value).intValue()); break; case LONG: output.writeByte(TYPE_ID_LONG); output.writeLong(((Long) value).longValue()); break; case SHORT: output.writeByte(TYPE_ID_SHORT); output.writeShort(((Short) value).shortValue()); break; case STRING: final String s = (String) value; if (STRING_COMPRESSION_ENABLED && s.length() >= STRING_COMPRESSION_MIN_SIZE) { output.writeByte(TYPE_ID_STRING_COMPRESSED); writeCompressedString(s, output); } else { output.writeByte(TYPE_ID_STRING); writeString(s, output, serializer); } break; case STRING_BYTES: final UTF8ByteDataHolder utfBytes = (UTF8ByteDataHolder) value; output.writeByte(TYPE_ID_STRING_BYTES); serializer.writeStringBytes(output, utfBytes.getBytes()); break; case STRING_BYTES_COMPRESSED: final UTF8ByteCompressedDataHolder utfCompressedBytes = (UTF8ByteCompressedDataHolder) value; output.writeByte(TYPE_ID_STRING_COMPRESSED); output.writeInt(utfCompressedBytes.getUncompressedStringLength()); writeByteArray(utfCompressedBytes.getBytes(), output); output.writeInt(utfCompressedBytes.getStringLength()); output.writeInt(utfCompressedBytes.getStringHash()); break; case OBJECT_ID: output.writeByte(TYPE_ID_REFERENCE); output.writeLong(((ObjectID) value).toLong()); break; case ARRAY: encodeArray(value, output); break; case OBJECT: default: throw Assert.failure("Illegal type (" + type + "):" + value); } // unreachable }