private void setProperties(Object object, UniqueId uniqueId, ByteBuf byteBuf) {
        ByteArrayReader reader = new ByteArrayReader(byteBuf);

        while(reader.available()) {
            int id = reader.readInt();
            UnsafeSetOp op = uniqueId.getUnsafeSetOp(id);
            Object value;
            int size;
            ArrayList<Object> list = new ArrayList<>();
            HashSet<Object> set = new HashSet<>();
            switch (op.getType()) {
                case SCHEMA_ID:
                    int length = reader.readInt();
                    value = reader.readString(length);
                    op.set(object, value);
                    break;
                case BYTE:
                    byte byteValue = (byte) reader.readByte();
                    op.set(object, byteValue);
                    break;
                case SHORT:
                    short shortVvalue = (short) reader.readShort();
                    op.set(object, shortVvalue);
                    break;
                case INTEGER:
                    int intValue = reader.readInt();
                    op.set(object, intValue);
                    break;
                case LONG:
                    long longValue = reader.readLong();
                    op.set(object, longValue);
                    break;
                case FLOAT:
                    float floatValue = reader.readFloat();
                    op.set(object, floatValue);
                    break;
                case DOUBLE:
                    double doubleValue = reader.readDouble();
                    op.set(object, doubleValue);
                    break;
                case STRING:
                    length = reader.readInt();
                    value = reader.readString(length);
                    op.set(object, value);
                    break;
                case BOOLEAN:
                    value = reader.readBoolean();
                    op.set(object, value);
                    break;
                case OBJECT:
                    length = reader.readInt();
                    value = conversion.convert(reader.readString(length), op.getObjectClass());
                    op.set(object, value);
                    break;
                case BYTE_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readByte());
                    }
                    op.set(object, list);
                    break;
                case SHORT_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readShort());
                    }
                    op.set(object, list);
                    break;
                case INTEGER_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readInt());
                    }
                    op.set(object, list);
                    break;
                case LONG_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readLong());
                    }
                    op.set(object, list);
                    break;
                case FLOAT_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readFloat());
                    }
                    op.set(object, list);
                    break;
                case DOUBLE_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readDouble());
                    }
                    op.set(object, list);
                    break;
                case STRING_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        length = reader.readInt();
                        list.add(reader.readString(length));
                    }
                    op.set(object, list);
                    break;
                case BOOLEAN_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        list.add(reader.readBoolean());
                    }
                    op.set(object, list);
                    break;
                case OBJECT_LIST:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        length = reader.readInt();
                        String stringValue = reader.readString(length);
                        value = conversion.convert(stringValue, op.getObjectClass());
                        list.add(value);
                    }
                    op.set(object, list);
                    break;
                case BYTE_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readByte());
                    }
                    op.set(object, set);
                    break;
                case SHORT_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readShort());
                    }
                    op.set(object, set);
                    break;
                case INTEGER_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readInt());
                    }
                    op.set(object, set);
                    break;
                case LONG_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readLong());
                    }
                    op.set(object, set);
                    break;
                case FLOAT_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readFloat());
                    }
                    op.set(object, set);
                    break;
                case DOUBLE_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readDouble());
                    }
                    op.set(object, set);
                    break;
                case STRING_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        length = reader.readInt();
                        set.add(reader.readString(length));
                    }
                    op.set(object, set);
                    break;
                case BOOLEAN_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        set.add(reader.readBoolean());
                    }
                    op.set(object, set);
                    break;
                case OBJECT_SET:
                    size = reader.readInt();
                    for (int i = 0; i < size; i++) {
                        length = reader.readInt();
                        String stringValue = reader.readString(length);
                        value = conversion.convert(stringValue, op.getObjectClass());
                        set.add(value);
                    }
                    op.set(object, set);
                    break;
                case REFERENCE_HOLDER:
                    Map<String, List<String>> references = new HashMap<>();
                    ConfigReferenceHolder holder = new ConfigReferenceHolder(references);
                    int numProperties = reader.readInt();
                    for (int i = 0; i < numProperties; i++) {
                        length = reader.readInt();
                        String property = reader.readString(length);
                        int numInstances = reader.readInt();
                        ArrayList<String> instances = new ArrayList<>();
                        for (int j = 0; j < numInstances; j++) {
                            length = reader.readInt();
                            instances.add(reader.readString(length));
                        }
                        references.put(property, instances);
                    }
                    op.set(object, holder);
                    break;
            }
        }
    }
private void setProperties ( Object object , UniqueId uniqueId , ByteBuf byteBuf ) { ByteArrayReader reader = new ByteArrayReader ( byteBuf ) ; while ( reader . available ( ) ) { int id = reader . readInt ( ) ; UnsafeSetOp op = uniqueId . getUnsafeSetOp ( id ) ; Object value ; int size ; ArrayList < Object > list = new ArrayList < > ( ) ; HashSet < Object > set = new HashSet < > ( ) ; switch ( op . getType ( ) ) { case SCHEMA_ID : int length = reader . readInt ( ) ; value = reader . readString ( length ) ; op . set ( object , value ) ; break ; case BYTE : byte byteValue = ( byte ) reader . readByte ( ) ; op . set ( object , byteValue ) ; break ; case SHORT : short shortVvalue = ( short ) reader . readShort ( ) ; op . set ( object , shortVvalue ) ; break ; case INTEGER : int intValue = reader . readInt ( ) ; op . set ( object , intValue ) ; break ; case LONG : long longValue = reader . readLong ( ) ; op . set ( object , longValue ) ; break ; case FLOAT : float floatValue = reader . readFloat ( ) ; op . set ( object , floatValue ) ; break ; case DOUBLE : double doubleValue = reader . readDouble ( ) ; op . set ( object , doubleValue ) ; break ; case STRING : length = reader . readInt ( ) ; value = reader . readString ( length ) ; op . set ( object , value ) ; break ; case BOOLEAN : value = reader . readBoolean ( ) ; op . set ( object , value ) ; break ; case OBJECT : length = reader . readInt ( ) ; value = conversion . convert ( reader . readString ( length ) , op . getObjectClass ( ) ) ; op . set ( object , value ) ; break ; case BYTE_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readByte ( ) ) ; } op . set ( object , list ) ; break ; case SHORT_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readShort ( ) ) ; } op . set ( object , list ) ; break ; case INTEGER_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readInt ( ) ) ; } op . set ( object , list ) ; break ; case LONG_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readLong ( ) ) ; } op . set ( object , list ) ; break ; case FLOAT_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readFloat ( ) ) ; } op . set ( object , list ) ; break ; case DOUBLE_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readDouble ( ) ) ; } op . set ( object , list ) ; break ; case STRING_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { length = reader . readInt ( ) ; list . add ( reader . readString ( length ) ) ; } op . set ( object , list ) ; break ; case BOOLEAN_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( reader . readBoolean ( ) ) ; } op . set ( object , list ) ; break ; case OBJECT_LIST : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { length = reader . readInt ( ) ; String stringValue = reader . readString ( length ) ; value = conversion . convert ( stringValue , op . getObjectClass ( ) ) ; list . add ( value ) ; } op . set ( object , list ) ; break ; case BYTE_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readByte ( ) ) ; } op . set ( object , set ) ; break ; case SHORT_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readShort ( ) ) ; } op . set ( object , set ) ; break ; case INTEGER_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readInt ( ) ) ; } op . set ( object , set ) ; break ; case LONG_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readLong ( ) ) ; } op . set ( object , set ) ; break ; case FLOAT_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readFloat ( ) ) ; } op . set ( object , set ) ; break ; case DOUBLE_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readDouble ( ) ) ; } op . set ( object , set ) ; break ; case STRING_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { length = reader . readInt ( ) ; set . add ( reader . readString ( length ) ) ; } op . set ( object , set ) ; break ; case BOOLEAN_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { set . add ( reader . readBoolean ( ) ) ; } op . set ( object , set ) ; break ; case OBJECT_SET : size = reader . readInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { length = reader . readInt ( ) ; String stringValue = reader . readString ( length ) ; value = conversion . convert ( stringValue , op . getObjectClass ( ) ) ; set . add ( value ) ; } op . set ( object , set ) ; break ; case REFERENCE_HOLDER : Map < String , List < String > > references = new HashMap < > ( ) ; ConfigReferenceHolder holder = new ConfigReferenceHolder ( references ) ; int numProperties = reader . readInt ( ) ; for ( int i = 0 ; i < numProperties ; i ++ ) { length = reader . readInt ( ) ; String property = reader . readString ( length ) ; int numInstances = reader . readInt ( ) ; ArrayList < String > instances = new ArrayList < > ( ) ; for ( int j = 0 ; j < numInstances ; j ++ ) { length = reader . readInt ( ) ; instances . add ( reader . readString ( length ) ) ; } references . put ( property , instances ) ; } op . set ( object , holder ) ; break ; } } }
This is where performance gets really important since we want to serialize each
off-heap ByteBuf into an instance and return it to the client as fast as possible.