private void generateEncodeBody(GeneratorAdapter mg, Schema schema, TypeToken<?> outputType,
                                  int value, int encoder, int schemaLocal, int seenRefs) {
    Schema.Type schemaType = schema.getType();

    switch (schemaType) {
      case NULL:
        break;
      case BOOLEAN:
        encodeSimple(mg, outputType, schema, "writeBool", value, encoder);
        break;
      case INT:
      case LONG:
      case FLOAT:
      case DOUBLE:
      case BYTES:
      case STRING:
        String encodeMethod = "write" + schemaType.name().charAt(0) + schemaType.name().substring(1).toLowerCase();
        encodeSimple(mg, outputType, schema, encodeMethod, value, encoder);
        break;
      case ENUM:
        encodeEnum(mg, outputType, value, encoder, schemaLocal);
        break;
      case ARRAY:
        if (Collection.class.isAssignableFrom(outputType.getRawType())) {
          Preconditions.checkArgument(outputType.getType() instanceof ParameterizedType,
                                      "Only support parameterized collection type.");
          TypeToken<?> componentType = TypeToken.of(((ParameterizedType) outputType.getType())
                                                      .getActualTypeArguments()[0]);

          encodeCollection(mg, componentType, schema.getComponentSchema(),
                           value, encoder, schemaLocal, seenRefs);
        } else if (outputType.isArray()) {
          TypeToken<?> componentType = outputType.getComponentType();
          encodeArray(mg, componentType, schema.getComponentSchema(),
                      value, encoder, schemaLocal, seenRefs);
        }
        break;
      case MAP:
        Preconditions.checkArgument(Map.class.isAssignableFrom(outputType.getRawType()),
                                    "Only %s type is supported.", Map.class.getName());
        Preconditions.checkArgument(outputType.getType() instanceof ParameterizedType,
                                    "Only support parameterized map type.");
        java.lang.reflect.Type[] mapArgs = ((ParameterizedType) outputType.getType()).getActualTypeArguments();
        Map.Entry<Schema, Schema> mapSchema = schema.getMapSchema();
        encodeMap(mg, TypeToken.of(mapArgs[0]), TypeToken.of(mapArgs[1]),
                  mapSchema.getKey(), mapSchema.getValue(), value, encoder, schemaLocal, seenRefs);
        break;
      case RECORD:
        encodeRecord(mg, schema, outputType, value, encoder, schemaLocal, seenRefs);
        break;
      case UNION:
        encodeUnion(mg, outputType, schema, value, encoder, schemaLocal, seenRefs);
        break;
    }
  }
private void generateEncodeBody ( GeneratorAdapter mg , Schema schema , TypeToken < ? > outputType , int value , int encoder , int schemaLocal , int seenRefs ) { Schema . Type schemaType = schema . getType ( ) ; switch ( schemaType ) { case NULL : break ; case BOOLEAN : encodeSimple ( mg , outputType , schema , "writeBool" , value , encoder ) ; break ; case INT : case LONG : case FLOAT : case DOUBLE : case BYTES : case STRING : String encodeMethod = "write" + schemaType . name ( ) . charAt ( 0 ) + schemaType . name ( ) . substring ( 1 ) . toLowerCase ( ) ; encodeSimple ( mg , outputType , schema , encodeMethod , value , encoder ) ; break ; case ENUM : encodeEnum ( mg , outputType , value , encoder , schemaLocal ) ; break ; case ARRAY : if ( Collection . class . isAssignableFrom ( outputType . getRawType ( ) ) ) { Preconditions . checkArgument ( outputType . getType ( ) instanceof ParameterizedType , "Only support parameterized collection type." ) ; TypeToken < ? > componentType = TypeToken . of ( ( ( ParameterizedType ) outputType . getType ( ) ) . getActualTypeArguments ( ) [ 0 ] ) ; encodeCollection ( mg , componentType , schema . getComponentSchema ( ) , value , encoder , schemaLocal , seenRefs ) ; } else if ( outputType . isArray ( ) ) { TypeToken < ? > componentType = outputType . getComponentType ( ) ; encodeArray ( mg , componentType , schema . getComponentSchema ( ) , value , encoder , schemaLocal , seenRefs ) ; } break ; case MAP : Preconditions . checkArgument ( Map . class . isAssignableFrom ( outputType . getRawType ( ) ) , "Only %s type is supported." , Map . class . getName ( ) ) ; Preconditions . checkArgument ( outputType . getType ( ) instanceof ParameterizedType , "Only support parameterized map type." ) ; java . lang . reflect . Type [ ] mapArgs = ( ( ParameterizedType ) outputType . getType ( ) ) . getActualTypeArguments ( ) ; Map . Entry < Schema , Schema > mapSchema = schema . getMapSchema ( ) ; encodeMap ( mg , TypeToken . of ( mapArgs [ 0 ] ) , TypeToken . of ( mapArgs [ 1 ] ) , mapSchema . getKey ( ) , mapSchema . getValue ( ) , value , encoder , schemaLocal , seenRefs ) ; break ; case RECORD : encodeRecord ( mg , schema , outputType , value , encoder , schemaLocal , seenRefs ) ; break ; case UNION : encodeUnion ( mg , outputType , schema , value , encoder , schemaLocal , seenRefs ) ; break ; } }
Generates the encode method body, with the binary encoder given in the local variable.
@param mg Method generator for generating method code body
@param schema Schema of the data to be encoded.