src/main/java/org/nustaq/serialization/FSTObjectOutput.java
protected void writeCompatibleObjectFields(Object toWrite, Map fields, FSTClazzInfo.FSTFieldInfo[] fieldInfo) throws IOException {
        int booleanMask = 0;
        int boolcount = 0;
        for (int i = 0; i < fieldInfo.length; i++) {
            try {
                FSTClazzInfo.FSTFieldInfo subInfo = fieldInfo[i];
                boolean isarr = subInfo.isArray();
                Class subInfType = subInfo.getType();
                if ( subInfType != boolean.class || isarr) {
                    if ( boolcount > 0 ) {
                        getCodec().writeFByte(booleanMask << (8 - boolcount));
                        boolcount = 0; booleanMask = 0;
                    }
                }
                if ( subInfo.isIntegral() && !isarr) {
                    if ( subInfType == boolean.class ) {
                        if ( boolcount == 8 ) {
                            getCodec().writeFByte(booleanMask << (8 - boolcount));
                            boolcount = 0; booleanMask = 0;
                        }
                        boolean booleanValue = ((Boolean)fields.get(subInfo.getName())).booleanValue();
                        booleanMask = booleanMask<<1;
                        booleanMask = (booleanMask|(booleanValue?1:0));
                        boolcount++;
                    } else
                    if ( subInfType == int.class ) {
                        getCodec().writeFInt(((Number) fields.get(subInfo.getName())).intValue());
                    } else
                    if ( subInfType == long.class ) {
                        getCodec().writeFLong(((Number) fields.get(subInfo.getName())).longValue());
                    } else
                    if ( subInfType == byte.class ) {
                        getCodec().writeFByte(((Number) fields.get(subInfo.getName())).byteValue());
                    } else
                    if ( subInfType == char.class ) {
                        getCodec().writeFChar((char) ((Number) fields.get(subInfo.getName())).intValue());
                    } else
                    if ( subInfType == short.class ) {
                        getCodec().writeFShort(((Number) fields.get(subInfo.getName())).shortValue());
                    } else
                    if ( subInfType == float.class ) {
                        getCodec().writeFFloat(((Number) fields.get(subInfo.getName())).floatValue());
                    } else
                    if ( subInfType == double.class ) {
                        getCodec().writeFDouble(((Number) fields.get(subInfo.getName())).doubleValue());
                    }
                } else {
                    // object
                    Object subObject = fields.get(subInfo.getName());
                    writeObjectWithContext(subInfo, subObject);
                }
            } catch (Exception ex) {
                FSTUtil.<RuntimeException>rethrow(ex);
            }
        }
        if ( boolcount > 0 ) {
            getCodec().writeFByte(booleanMask << (8 - boolcount));
        }
    }
protected void writeCompatibleObjectFields(Object toWrite, Map fields, FSTClazzInfo.FSTFieldInfo[] fieldInfo) throws IOException {
        int booleanMask = 0;
        int boolcount = 0;
        for (int i = 0; i < fieldInfo.length; i++) {
            try {
                FSTClazzInfo.FSTFieldInfo subInfo = fieldInfo[i];
                boolean isarr = subInfo.isArray();
                Class subInfType = subInfo.getType();
                if ( subInfType != boolean.class || isarr) {
                    if ( boolcount > 0 ) {
                        getCodec().writeFByte(booleanMask << (8 - boolcount));
                        boolcount = 0; booleanMask = 0;
                    }
                }
                if ( subInfo.isIntegral() && !isarr) {
                    if ( subInfType == boolean.class ) {
                        if ( boolcount == 8 ) {
                            getCodec().writeFByte(booleanMask << (8 - boolcount));
                            boolcount = 0; booleanMask = 0;
                        }
                        boolean booleanValue = ((Boolean)fields.get(subInfo.getName())).booleanValue();
                        booleanMask = booleanMask<<1;
                        booleanMask = (booleanMask|(booleanValue?1:0));
                        boolcount++;
                    } else
                    if ( subInfType == int.class ) {
                        getCodec().writeFInt(((Number) fields.get(subInfo.getName())).intValue());
                    } else
                    if ( subInfType == long.class ) {
                        getCodec().writeFLong(((Number) fields.get(subInfo.getName())).longValue());
                    } else
                    if ( subInfType == byte.class ) {
                        getCodec().writeFByte(((Number) fields.get(subInfo.getName())).byteValue());
                    } else
                    if ( subInfType == char.class ) {
                        getCodec().writeFChar((char) ((Number) fields.get(subInfo.getName())).intValue());
                    } else
                    if ( subInfType == short.class ) {
                        getCodec().writeFShort(((Number) fields.get(subInfo.getName())).shortValue());
                    } else
                    if ( subInfType == float.class ) {
                        getCodec().writeFFloat(((Number) fields.get(subInfo.getName())).floatValue());
                    } else
                    if ( subInfType == double.class ) {
                        getCodec().writeFDouble(((Number) fields.get(subInfo.getName())).doubleValue());
                    }
                } else {
                    // object
                    Object subObject = fields.get(subInfo.getName());
                    writeObjectWithContext(subInfo, subObject);
                }
            } catch (Exception ex) {
                FSTUtil.<RuntimeException>rethrow(ex);
            }
        }
        if ( boolcount > 0 ) {
            getCodec().writeFByte(booleanMask << (8 - boolcount));
        }
    }
protected void writeCompatibleObjectFields ( Object toWrite , Map fields , FSTClazzInfo . FSTFieldInfo [ ] fieldInfo ) throws IOException { int booleanMask = 0 ; int boolcount = 0 ; for ( int i = 0 ; i < fieldInfo . length ; i ++ ) { try { FSTClazzInfo . FSTFieldInfo subInfo = fieldInfo [ i ] ; boolean isarr = subInfo . isArray ( ) ; Class subInfType = subInfo . getType ( ) ; if ( subInfType != boolean . class || isarr ) { if ( boolcount > 0 ) { getCodec ( ) . writeFByte ( booleanMask << ( 8 - boolcount ) ) ; boolcount = 0 ; booleanMask = 0 ; } } if ( subInfo . isIntegral ( ) && ! isarr ) { if ( subInfType == boolean . class ) { if ( boolcount == 8 ) { getCodec ( ) . writeFByte ( booleanMask << ( 8 - boolcount ) ) ; boolcount = 0 ; booleanMask = 0 ; } boolean booleanValue = ( ( Boolean ) fields . get ( subInfo . getName ( ) ) ) . booleanValue ( ) ; booleanMask = booleanMask << 1 ; booleanMask = ( booleanMask | ( booleanValue ? 1 : 0 ) ) ; boolcount ++ ; } else if ( subInfType == int . class ) { getCodec ( ) . writeFInt ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . intValue ( ) ) ; } else if ( subInfType == long . class ) { getCodec ( ) . writeFLong ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . longValue ( ) ) ; } else if ( subInfType == byte . class ) { getCodec ( ) . writeFByte ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . byteValue ( ) ) ; } else if ( subInfType == char . class ) { getCodec ( ) . writeFChar ( ( char ) ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . intValue ( ) ) ; } else if ( subInfType == short . class ) { getCodec ( ) . writeFShort ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . shortValue ( ) ) ; } else if ( subInfType == float . class ) { getCodec ( ) . writeFFloat ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . floatValue ( ) ) ; } else if ( subInfType == double . class ) { getCodec ( ) . writeFDouble ( ( ( Number ) fields . get ( subInfo . getName ( ) ) ) . doubleValue ( ) ) ; } } else { // object Object subObject = fields . get ( subInfo . getName ( ) ) ; writeObjectWithContext ( subInfo , subObject ) ; } } catch ( Exception ex ) { FSTUtil . < RuntimeException > rethrow ( ex ) ; } } if ( boolcount > 0 ) { getCodec ( ) . writeFByte ( booleanMask << ( 8 - boolcount ) ) ; } }
write identical to other version, but take field values from hashmap (because of annoying putField/getField feature)
write identical to other version but take field values from hashmap ( because of annoying putField / getField feature )