Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   //========================================================================
   //Copyright 2007-2011 David Yu dyuproject@gmail.com
   //------------------------------------------------------------------------
   //Licensed under the Apache License, Version 2.0 (the "License");
   //you may not use this file except in compliance with the License.
   //You may obtain a copy of the License at 
   //http://www.apache.org/licenses/LICENSE-2.0
   //Unless required by applicable law or agreed to in writing, software
   //distributed under the License is distributed on an "AS IS" BASIS,
  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  //See the License for the specific language governing permissions and
  //limitations under the License.
  //========================================================================
  
  package io.protostuff.runtime;
  
  import static io.protostuff.runtime.RuntimeFieldFactory.BIGDECIMAL;
  import static io.protostuff.runtime.RuntimeFieldFactory.BIGINTEGER;
  import static io.protostuff.runtime.RuntimeFieldFactory.BOOL;
  import static io.protostuff.runtime.RuntimeFieldFactory.BYTE;
  import static io.protostuff.runtime.RuntimeFieldFactory.BYTES;
  import static io.protostuff.runtime.RuntimeFieldFactory.BYTE_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.CHAR;
  import static io.protostuff.runtime.RuntimeFieldFactory.DATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.DOUBLE;
  import static io.protostuff.runtime.RuntimeFieldFactory.FLOAT;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY_DELEGATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY_POJO;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ARRAY_SCALAR;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BIGDECIMAL;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BIGINTEGER;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BOOL;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BYTE;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BYTES;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_BYTE_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_CHAR;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_CLASS;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_CLASS_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_CLASS_ARRAY_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_CLASS_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_DATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_DELEGATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_DOUBLE;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM_SET;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_FLOAT;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_INT32;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_INT64;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_OBJECT;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_POJO;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_POLYMORPHIC_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_POLYMORPHIC_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_SHORT;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_STRING;
  import static io.protostuff.runtime.RuntimeFieldFactory.ID_THROWABLE;
  import static io.protostuff.runtime.RuntimeFieldFactory.INT32;
  import static io.protostuff.runtime.RuntimeFieldFactory.INT64;
  import static io.protostuff.runtime.RuntimeFieldFactory.SHORT;
  import static io.protostuff.runtime.RuntimeFieldFactory.STRING;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY_DELEGATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY_POJO;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ARRAY_SCALAR;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BIGDECIMAL;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BIGINTEGER;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BOOL;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BYTE;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BYTES;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_BYTE_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_CHAR;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_CLASS;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_CLASS_ARRAY;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_CLASS_ARRAY_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_CLASS_MAPPED;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_DATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_DELEGATE;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_DOUBLE;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM_SET;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_FLOAT;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_INT32;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_INT64;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_OBJECT;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_POJO;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_POLYMOPRHIC_MAP;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_POLYMORPHIC_COLLECTION;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_SHORT;
  import static io.protostuff.runtime.RuntimeFieldFactory.STR_STRING;
 import static io.protostuff.runtime.RuntimeFieldFactory.STR_THROWABLE;
 
 import java.util.Map;
 
A schema for dynamic types (fields where the type is java.lang.Object).

Author(s):
David Yu
Created:
Feb 1, 2011
 
 public abstract class ObjectSchema extends PolymorphicSchema
 {
 
     static final int ID_ENUM_VALUE = 1;
     static final int ID_ARRAY_LEN = 3;
     static final int ID_ARRAY_DIMENSION = 2;
 
     static String name(int number)
     {
         switch (number)
         {
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
 
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
 
             case :
                 return ;
 
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
 
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
             case :
                 return ;
 
             case :
                 return ;
             default:
                 return null;
         }
     }
 
     static int number(String name)
     {
         if (name.length() != 1)
             return 0;
 
         switch (name.charAt(0))
         {
             case 'B':
                 return 28;
             case 'C':
                 return 29;
             case 'D':
                 return 30;
 
             case 'F':
                 return 32;
             case 'G':
                 return 33;
             case 'H':
                 return 34;
             case 'I':
                 return 35;
 
             case 'Z':
                 return 52;
             case '_':
                 return 127;
 
             case 'a':
                 return 1;
             case 'b':
                 return 2;
             case 'c':
                 return 3;
             case 'd':
                 return 4;
             case 'e':
                 return 5;
             case 'f':
                 return 6;
             case 'g':
                 return 7;
             case 'h':
                 return 8;
             case 'i':
                 return 9;
             case 'j':
                 return 10;
             case 'k':
                 return 11;
             case 'l':
                 return 12;
             case 'm':
                 return 13;
             case 'n':
                 return 14;
             case 'o':
                 return 15;
             case 'p':
                 return 16;
             case 'q':
                 return 17;
             case 'r':
                 return 18;
             case 's':
                 return 19;
             case 't':
                 return 20;
             case 'u':
                 return 21;
 
             case 'v':
                 return 22;
             case 'w':
                 return 23;
             case 'x':
                 return 24;
             case 'y':
                 return 25;
             case 'z':
                 return 26;
             default:
                 return 0;
         }
     }
 
     protected final Pipe.Schema<ObjectpipeSchema = new Pipe.Schema<Object>(this)
     {
         @Override
         protected void transfer(Pipe pipeInput inputOutput outputthrows IOException
         {
             transferObject(thispipeinputoutput);
         }
     };
 
     public ObjectSchema(IdStrategy strategy)
     {
         super(strategy);
     }
 
     @Override
     public Pipe.Schema<ObjectgetPipeSchema()
     {
         return ;
     }
 
     @Override
     public String getFieldName(int number)
     {
         return name(number);
     }
 
     @Override
     public int getFieldNumber(String name)
     {
         return number(name);
     }
 
     @Override
     public String messageFullName()
     {
         return Object.class.getName();
     }
 
     @Override
     public String messageName()
     {
         return Object.class.getSimpleName();
     }
 
     @Override
     public void mergeFrom(Input inputObject ownerthrows IOException
     {
         setValue(readObjectFrom(inputthisowner), owner);
     }
 
     @Override
     public void writeTo(Output outputObject valuethrows IOException
     {
         writeObjectTo(outputvaluethis);
     }
 
     static ArrayWrapper newArrayWrapper(Input inputSchema<?> schema,
             boolean mappedIdStrategy strategythrows IOException
     {
         final Class<?> componentType = strategy.resolveArrayComponentTypeFrom(
                 inputmapped);
 
         if (input.readFieldNumber(schema) != )
             throw new ProtostuffException("Corrupt input.");
         final int len = input.readUInt32();
 
         if (input.readFieldNumber(schema) != )
             throw new ProtostuffException("Corrupt input.");
         final int dimensions = input.readUInt32();
 
         if (dimensions == 1)
             return new ArrayWrapper(Array.newInstance(componentTypelen));
 
         final int[] arg = new int[dimensions];
         arg[0] = len;
         return new ArrayWrapper(Array.newInstance(componentTypearg));
     }
 
     static void transferArray(Pipe pipeInput inputOutput outputint number,
             Pipe.Schema<?> pipeSchemaboolean mappedIdStrategy strategythrows IOException
     {
         strategy.transferArrayId(inputoutputnumbermapped);
 
         if (input.readFieldNumber(pipeSchema.wrappedSchema) != )
             throw new ProtostuffException("Corrupt input.");
 
         output.writeUInt32(input.readUInt32(), false);
 
         if (input.readFieldNumber(pipeSchema.wrappedSchema) != )
             throw new ProtostuffException("Corrupt input.");
 
         output.writeUInt32(input.readUInt32(), false);
 
         if (output instanceof StatefulOutput)
         {
             // update using the derived schema.
             ((StatefulOutputoutput).updateLast(strategy.ARRAY_PIPE_SCHEMApipeSchema);
         }
 
         Pipe.transferDirect(strategy.ARRAY_PIPE_SCHEMApipeinputoutput);
     }
 
     static void transferClass(Pipe pipeInput inputOutput outputint number,
             Pipe.Schema<?> pipeSchemaboolean mappedboolean array,
             IdStrategy strategythrows IOException
     {
         strategy.transferClassId(inputoutputnumbermappedarray);
 
         if (array)
         {
             if (input.readFieldNumber(pipeSchema.wrappedSchema) != )
                 throw new ProtostuffException("Corrupt input.");
 
             output.writeUInt32(input.readUInt32(), false);
         }
     }
 
     static Class<?> getArrayClass(Input inputSchema<?> schema,
             final Class<?> componentTypethrows IOException
     {
         if (input.readFieldNumber(schema) != )
             throw new ProtostuffException("Corrupt input.");
         final int dimensions = input.readUInt32();
 
         // TODO is there another way (reflection) to obtain an array class?
 
         if (dimensions == 1)
             return Array.newInstance(componentType, 0).getClass();
 
         final int[] arg = new int[dimensions];
         arg[0] = 0;
         return Array.newInstance(componentTypearg).getClass();
     }
 
     @SuppressWarnings("unchecked")
     static Object readObjectFrom(final Input inputfinal Schema<?> schema,
             Object ownerIdStrategy strategythrows IOException
     {
         Object value = null;
         final int number = input.readFieldNumber(schema);
         switch (number)
         {
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
             case :
                 value = .readFrom(input);
                 break;
 
             case :
             {
                 final ArrayWrapper arrayWrapper = newArrayWrapper(inputschemafalse,
                         strategy);
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(arrayWrapper.arrayowner);
                 }
 
                 strategy.COLLECTION_SCHEMA.mergeFrom(inputarrayWrapper);
 
                 return arrayWrapper.array;
             }
             case :
                 if (input.readUInt32() != 0)
                     throw new ProtostuffException("Corrupt input.");
 
                 value = new Object();
 
                 break;
 
             case :
             {
                 final ArrayWrapper mArrayWrapper = newArrayWrapper(inputschematrue,
                         strategy);
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(mArrayWrapper.arrayowner);
                 }
 
                 strategy.COLLECTION_SCHEMA.mergeFrom(inputmArrayWrapper);
 
                 return mArrayWrapper.array;
             }
             case :
                 value = strategy.resolveClassFrom(inputfalsefalse);
                 break;
             case :
                 value = strategy.resolveClassFrom(inputtruefalse);
                 break;
             case :
                 value = getArrayClass(inputschema,
                         strategy.resolveClassFrom(inputfalsetrue));
                 break;
             case :
                 value = getArrayClass(inputschema,
                         strategy.resolveClassFrom(inputtruetrue));
                 break;
 
             case :
             {
                 final EnumIO<?> eio = strategy.resolveEnumFrom(input);
 
                 if (input.readFieldNumber(schema) != )
                     throw new ProtostuffException("Corrupt input.");
 
                 value = eio.readFrom(input);
                 break;
             }
             case :
             {
                 final Collection<?> es = strategy.resolveEnumFrom(input).newEnumSet();
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(esowner);
                 }
 
                 strategy.COLLECTION_SCHEMA.mergeFrom(input, (Collection<Object>) es);
 
                 return es;
             }
             case :
             {
                 final Map<?, Objectem = strategy.resolveEnumFrom(input).newEnumMap();
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(emowner);
                 }
 
                 strategy.MAP_SCHEMA.mergeFrom(input, (Map<ObjectObject>) em);
 
                 return em;
             }
             case :
             {
                 final Collection<Objectcollection = strategy.resolveCollectionFrom(
                         input).newMessage();
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 strategy.COLLECTION_SCHEMA.mergeFrom(inputcollection);
 
                 return collection;
             }
             case :
             {
                 final Map<ObjectObjectmap =
                         strategy.resolveMapFrom(input).newMessage();
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(mapowner);
                 }
 
                 strategy.MAP_SCHEMA.mergeFrom(inputmap);
 
                 return map;
             }
             case :
             {
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 final Object collection = PolymorphicCollectionSchema.readObjectFrom(input,
                         strategy.POLYMORPHIC_COLLECTION_SCHEMAownerstrategy);
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(collectionowner);
                 }
 
                 return collection;
             }
             case :
             {
                 if (0 != input.readUInt32())
                     throw new ProtostuffException("Corrupt input.");
 
                 final Object map = PolymorphicMapSchema.readObjectFrom(input,
                         strategy.POLYMORPHIC_MAP_SCHEMAownerstrategy);
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(mapowner);
                 }
 
                 return map;
             }
             case :
             {
                 final HasDelegate<Objecthd = strategy.resolveDelegateFrom(input);
                 if (1 != input.readFieldNumber(schema))
                     throw new ProtostuffException("Corrupt input.");
 
                 value = hd.delegate.readFrom(input);
                 break;
             }
             case :
             {
                 final HasDelegate<Objecthd = strategy.resolveDelegateFrom(input);
 
                 return hd.genericElementSchema.readFrom(inputowner);
             }
             case :
             {
                 final int arrayId = input.readUInt32(), id = ArraySchemas.toInlineId(arrayId);
 
                 final ArraySchemas.Base arraySchema = ArraySchemas.getSchema(id,
                         ArraySchemas.isPrimitive(arrayId));
 
                 return arraySchema.readFrom(inputowner);
             }
             case :
             {
                 final EnumIO<?> eio = strategy.resolveEnumFrom(input);
 
                 return eio.genericElementSchema.readFrom(inputowner);
             }
             case :
             {
                 final HasSchema<Objecths = strategy.resolvePojoFrom(inputnumber);
 
                 return hs.genericElementSchema.readFrom(inputowner);
             }
             case :
                 return PolymorphicThrowableSchema.readObjectFrom(inputschemaowner,
                         strategynumber);
             case :
             {
                 final Schema<ObjectderivedSchema = strategy.resolvePojoFrom(
                         inputnumber).getSchema();
 
                 final Object pojo = derivedSchema.newMessage();
 
                 if (input instanceof GraphInput)
                 {
                     // update the actual reference.
                     ((GraphInputinput).updateLast(pojoowner);
                 }
 
                 derivedSchema.mergeFrom(inputpojo);
                 return pojo;
             }
             default:
                 throw new ProtostuffException("Corrupt input.  Unknown field number: " + number);
         }
 
         if (input instanceof GraphInput)
         {
             // update the actual reference.
             ((GraphInputinput).updateLast(valueowner);
         }
 
         if (input.readFieldNumber(schema) != 0)
             throw new ProtostuffException("Corrupt input.");
 
         return value;
     }
 
     @SuppressWarnings("unchecked")
     static void writeObjectTo(Output outputObject value,
             Schema<?> currentSchemaIdStrategy strategythrows IOException
     {
         final Class<Objectclazz = (Class<Object>) value.getClass();
 
         final HasDelegate<Objecthd = strategy.tryWriteDelegateIdTo(output,
                 clazz);
 
         if (hd != null)
         {
             hd.delegate.writeTo(output, 1, valuefalse);
             return;
         }
 
         final RuntimeFieldFactory<Objectinline = RuntimeFieldFactory.getInline(clazz);
         if (inline != null)
         {
             // scalar value
             inline.writeTo(outputinline.idvaluefalse);
             return;
         }
 
         if (Message.class.isAssignableFrom(clazz))
         {
             final Schema<Objectschema = strategy.writeMessageIdTo(
                     output, (Message<Object>) value);
 
             if (output instanceof StatefulOutput)
             {
                 // update using the derived schema.
                 ((StatefulOutputoutput).updateLast(schemacurrentSchema);
             }
 
             schema.writeTo(outputvalue);
             return;
         }
 
         if (clazz.isEnum())
         {
             EnumIO<?> eio = strategy.getEnumIO(clazz);
             strategy.writeEnumIdTo(outputclazz);
             eio.writeTo(outputfalse, (Enum<?>) value);
             return;
         }
 
         if (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())
         {
             EnumIO<?> eio = strategy.getEnumIO(clazz.getSuperclass());
             strategy.writeEnumIdTo(outputclazz.getSuperclass());
             eio.writeTo(outputfalse, (Enum<?>) value);
             return;
         }
 
         if (clazz.isArray())
         {
             Class<?> componentType = clazz.getComponentType();
 
             final HasDelegate<ObjecthdArray = strategy.tryWriteDelegateIdTo(output,
                     , (Class<Object>) componentType);
 
             if (hdArray != null)
             {
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(hdArray.genericElementSchema,
                             currentSchema);
                 }
 
                 hdArray.genericElementSchema.writeTo(outputvalue);
                 return;
             }
 
             final RuntimeFieldFactory<?> inlineArray = RuntimeFieldFactory.getInline(
                     componentType);
             if (inlineArray != null)
             {
                 // scalar
                 final boolean primitive = componentType.isPrimitive();
                 final ArraySchemas.Base arraySchema = ArraySchemas.getSchema(
                         inlineArray.idprimitive);
 
                 output.writeUInt32(,
                         ArraySchemas.toArrayId(inlineArray.idprimitive),
                         false);
 
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(arraySchemacurrentSchema);
                 }
 
                 arraySchema.writeTo(outputvalue);
                 return;
             }
 
             if (componentType.isEnum())
             {
                 // enum
                 final EnumIO<?> eio = strategy.getEnumIO(componentType);
 
                 strategy.writeEnumIdTo(outputcomponentType);
 
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(eio.genericElementSchema,
                             currentSchema);
                 }
 
                 eio.genericElementSchema.writeTo(outputvalue);
                 return;
             }
 
             if (Message.class.isAssignableFrom(componentType) ||
                     strategy.isRegistered(componentType))
             {
                 // messsage / registered pojo
                 final HasSchema<Objecths = strategy.writePojoIdTo(output,
                         , (Class<Object>) componentType);
 
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(hs.genericElementSchema,
                             currentSchema);
                 }
 
                 hs.genericElementSchema.writeTo(outputvalue);
                 return;
             }
 
             /*
              * if(!Throwable.class.isAssignableFrom(componentType)) { boolean create =
              * Message.class.isAssignableFrom(componentType); HasSchema<Object> hs = strategy.getSchemaWrapper(
              * (Class<Object>)componentType, create); if(hs != null) {
              * 
              * } }
              */
 
             // complex type
             int dimensions = 1;
             while (componentType.isArray())
             {
                 dimensions++;
                 componentType = componentType.getComponentType();
             }
 
             strategy.writeArrayIdTo(outputcomponentType);
             // write the length of the array
             output.writeUInt32(, Array.getLength(value), false);
             // write the dimensions of the array
             output.writeUInt32(dimensionsfalse);
 
             if (output instanceof StatefulOutput)
             {
                 // update using the derived schema.
                 ((StatefulOutputoutput).updateLast(strategy.ARRAY_SCHEMAcurrentSchema);
             }
 
             strategy.ARRAY_SCHEMA.writeTo(outputvalue);
             return;
         }
 
         if (Object.class == clazz)
         {
             output.writeUInt32(, 0, false);
             return;
         }
 
         if (Class.class == value.getClass())
         {
             // its a class
             final Class<?> c = ((Class<?>) value);
             if (c.isArray())
             {
                 int dimensions = 1;
                 Class<?> componentType = c.getComponentType();
                 while (componentType.isArray())
                 {
                     dimensions++;
                     componentType = componentType.getComponentType();
                 }
 
                 strategy.writeClassIdTo(outputcomponentTypetrue);
                 // write the dimensions of the array
                 output.writeUInt32(dimensionsfalse);
                 return;
             }
 
             strategy.writeClassIdTo(outputcfalse);
             return;
         }
 
         if (Map.class.isAssignableFrom(clazz))
         {
             if (Collections.class == clazz.getDeclaringClass())
             {
                 output.writeUInt32(, 0, false);
 
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(
                             strategy.POLYMORPHIC_MAP_SCHEMAcurrentSchema);
                 }
 
                 PolymorphicMapSchema.writeNonPublicMapTo(outputvalue,
                         strategy.POLYMORPHIC_MAP_SCHEMAstrategy);
                 return;
             }
 
             if (EnumMap.class.isAssignableFrom(clazz))
             {
                 strategy.writeEnumIdTo(output,
                         EnumIO.getKeyTypeFromEnumMap(value));
             }
             else
             {
                 strategy.writeMapIdTo(outputclazz);
             }
 
             if (output instanceof StatefulOutput)
             {
                 // update using the derived schema.
                 ((StatefulOutputoutput).updateLast(strategy.MAP_SCHEMAcurrentSchema);
             }
 
             strategy.MAP_SCHEMA.writeTo(output, (Map<ObjectObject>) value);
             return;
         }
 
         if (Collection.class.isAssignableFrom(clazz))
         {
             if (Collections.class == clazz.getDeclaringClass())
             {
                 output.writeUInt32(, 0, false);
 
                 if (output instanceof StatefulOutput)
                 {
                     // update using the derived schema.
                     ((StatefulOutputoutput).updateLast(
                             strategy.POLYMORPHIC_COLLECTION_SCHEMAcurrentSchema);
                 }
 
                 PolymorphicCollectionSchema.writeNonPublicCollectionTo(outputvalue,
                         strategy.POLYMORPHIC_COLLECTION_SCHEMAstrategy);
                 return;
             }
 
             if (EnumSet.class.isAssignableFrom(clazz))
             {
                 strategy.writeEnumIdTo(output,
                         EnumIO.getElementTypeFromEnumSet(value));
             }
             else
             {
                 strategy.writeCollectionIdTo(outputclazz);
             }
 
             if (output instanceof StatefulOutput)
             {
                 // update using the derived schema.
                 ((StatefulOutputoutput).updateLast(strategy.COLLECTION_SCHEMAcurrentSchema);
             }
 
             strategy.COLLECTION_SCHEMA.writeTo(output, (Collection<Object>) value);
             return;
         }
 
         if (Throwable.class.isAssignableFrom(clazz))
         {
             // throwable
             PolymorphicThrowableSchema.writeObjectTo(outputvaluecurrentSchema,
                     strategy);
             return;
         }
 
         // pojo
         final Schema<Objectschema = strategy.writePojoIdTo(
                 outputclazz).getSchema();
 
         if (output instanceof StatefulOutput)
         {
             // update using the derived schema.
             ((StatefulOutputoutput).updateLast(schemacurrentSchema);
         }
        schema.writeTo(outputvalue);
    }
    static void transferObject(Pipe.Schema<ObjectpipeSchemaPipe pipe,
            Input inputOutput outputIdStrategy strategythrows IOException
    {
        final int number = input.readFieldNumber(pipeSchema.wrappedSchema);
        switch (number)
        {
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                .transfer(pipeinputoutputnumberfalse);
                break;
            case :
                transferArray(pipeinputoutputnumberpipeSchemafalsestrategy);
                return;
            case :
                output.writeUInt32(numberinput.readUInt32(), false);
                break;
            case :
                transferArray(pipeinputoutputnumberpipeSchematruestrategy);
                return;
            case :
                transferClass(pipeinputoutputnumberpipeSchemafalsefalsestrategy);
                break;
            case :
                transferClass(pipeinputoutputnumberpipeSchematruefalsestrategy);
                break;
            case :
                transferClass(pipeinputoutputnumberpipeSchemafalsetruestrategy);
                break;
            case :
                transferClass(pipeinputoutputnumberpipeSchematruetruestrategy);
                break;
            case :
            {
                strategy.transferEnumId(inputoutputnumber);
                if (input.readFieldNumber(pipeSchema.wrappedSchema) != )
                    throw new ProtostuffException("Corrupt input.");
                EnumIO.transfer(pipeinputoutput, 1, false);
                break;
            }
            case :
            {
                strategy.transferEnumId(inputoutputnumber);
                if (output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutputoutput).updateLast(strategy.COLLECTION_PIPE_SCHEMApipeSchema);
                }
                Pipe.transferDirect(strategy.COLLECTION_PIPE_SCHEMApipeinputoutput);
                return;
            }