protected void initEncodeMethodTemplateVariable ( ) { Set < Integer > orders = new HashSet < Integer > ( ) ; // encode method for ( FieldInfo field : fields ) { boolean isList = field . isList ( ) ; // check type if ( ! isList ) { checkType ( field . getFieldType ( ) , field . getField ( ) ) ; } if ( orders . contains ( field . getOrder ( ) ) ) { throw new IllegalArgumentException ( "Field order '" + field . getOrder ( ) + "' on field" + field . getField ( ) . getName ( ) + " already exsit." ) ; } // define field FieldType fieldType = field . getFieldType ( ) ; String accessByField = getAccessByField ( "t" , field . getField ( ) , cls ) ; String fieldName = CodedConstant . getFieldName ( field . getOrder ( ) ) ; String encodeFieldType = CodedConstant . getFiledType ( fieldType , isList ) ; templator . setVariable ( "encodeFieldType" , encodeFieldType ) ; templator . setVariable ( "encodeFieldName" , fieldName ) ; templator . setVariable ( "encodeFieldGetter" , accessByField ) ; String writeValueToField = CodedConstant . getWriteValueToField ( fieldType , accessByField , isList ) ; templator . setVariable ( "writeValueToField" , writeValueToField ) ; if ( field . isRequired ( ) ) { templator . setVariableOpt ( "checkNull" , CodedConstant . getRequiredCheck ( field . getOrder ( ) , field . getField ( ) ) ) ; } else { templator . setVariable ( "checkNull" , "" ) ; } String calcSize = CodedConstant . getMappedTypeSize ( field , field . getOrder ( ) , field . getFieldType ( ) , isList , debug , outputPath ) ; templator . setVariable ( "calcSize" , calcSize ) ; // set write to byte String encodeWriteFieldValue = CodedConstant . getMappedWriteCode ( field , "output" , field . getOrder ( ) , field . getFieldType ( ) , isList ) ; templator . setVariable ( "encodeWriteFieldValue" , encodeWriteFieldValue ) ; templator . addBlock ( "encodeFields" ) ; } }
Inits the encode method template variable .