Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //================================================================================
  //Copyright (c) 2012, David Yu
  //All rights reserved.
  //--------------------------------------------------------------------------------
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are met:
  // 1. Redistributions of source code must retain the above copyright notice,
  //    this list of conditions and the following disclaimer.
  // 2. Redistributions in binary form must reproduce the above copyright notice,
 //    this list of conditions and the following disclaimer in the documentation
 //    and/or other materials provided with the distribution.
 // 3. Neither the name of protostuff nor the names of its contributors may be used
 //    to endorse or promote products derived from this software without
 //    specific prior written permission.
 //
 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 // POSSIBILITY OF SUCH DAMAGE.
 //================================================================================
 
 package io.protostuff.runtime;
 
 import static io.protostuff.runtime.RuntimeFieldFactory.ID_ENUM_MAP;
 import static io.protostuff.runtime.RuntimeFieldFactory.ID_MAP;
 import static io.protostuff.runtime.RuntimeFieldFactory.STR_ENUM_MAP;
 import static io.protostuff.runtime.RuntimeFieldFactory.STR_MAP;
 
 import java.util.Map;
 
Used when the type is an interface (Map/SortedMap).

Author(s):
David Yu
Created:
Apr 24, 2012
 
 public abstract class PolymorphicMapSchema extends PolymorphicSchema
 {
 
     static final int ID_EMPTY_MAP = 1, ID_SINGLETON_MAP = 2,
             ID_UNMODIFIABLE_MAP = 3, ID_UNMODIFIABLE_SORTED_MAP = 4,
             ID_SYNCHRONIZED_MAP = 5, ID_SYNCHRONIZED_SORTED_MAP = 6,
             ID_CHECKED_MAP = 7, ID_CHECKED_SORTED_MAP = 8;
 
     static final String STR_EMPTY_MAP = "a"STR_SINGLETON_MAP = "b",
             STR_UNMODIFIABLE_MAP = "c"STR_UNMODIFIABLE_SORTED_MAP = "d",
             STR_SYNCHRONIZED_MAP = "e"STR_SYNCHRONIZED_SORTED_MAP = "f",
             STR_CHECKED_MAP = "g"STR_CHECKED_SORTED_MAP = "h";
 
     static final IdentityHashMap<Class<?>, Integer__nonPublicMaps = new IdentityHashMap<Class<?>, Integer>();
 
     static final Field fSingletonMap_kfSingletonMap_v,
 
             fUnmodifiableMap_m,
 
             fUnmodifiableSortedMap_sm,
 
             fSynchronizedMap_m,
 
             fSynchronizedSortedMap_sm,
 
             fSynchronizedMap_mutex,
 
             fCheckedMap_valueType;
 
     static final Instantiator<?> iSingletonMap,
 
             iUnmodifiableMapiUnmodifiableSortedMap,
 
             iSynchronizedMapiSynchronizedSortedMap,
 
             iCheckedMapiCheckedSortedMap;
 
     static
     {
        map("java.util.Collections$EmptyMap");
        Class<?> cSingletonMap = map("java.util.Collections$SingletonMap",
                );
        Class<?> cUnmodifiableMap = map(
                "java.util.Collections$UnmodifiableMap");
        Class<?> cUnmodifiableSortedMap = map(
                "java.util.Collections$UnmodifiableSortedMap",
                );
        Class<?> cSynchronizedMap = map(
                "java.util.Collections$SynchronizedMap");
        Class<?> cSynchronizedSortedMap = map(
                "java.util.Collections$SynchronizedSortedMap",
                );
        Class<?> cCheckedMap = map("java.util.Collections$CheckedMap",
                );
        Class<?> cCheckedSortedMap = map(
                "java.util.Collections$CheckedSortedMap");
        try
        {
             = cSingletonMap.getDeclaredField("k");
             = cSingletonMap.getDeclaredField("v");
             = cUnmodifiableMap.getDeclaredField("m");
             = cUnmodifiableSortedMap
                    .getDeclaredField("sm");
             = cSynchronizedMap.getDeclaredField("m");
             = cSynchronizedSortedMap
                    .getDeclaredField("sm");
             = cSynchronizedMap.getDeclaredField("mutex");
             = cCheckedMap.getDeclaredField("m");
             = cCheckedSortedMap.getDeclaredField("sm");
             = cCheckedMap.getDeclaredField("keyType");
             = cCheckedMap.getDeclaredField("valueType");
             = RuntimeEnv.newInstantiator(cSingletonMap);
             = RuntimeEnv.newInstantiator(cUnmodifiableMap);
             = RuntimeEnv
                    .newInstantiator(cUnmodifiableSortedMap);
             = RuntimeEnv.newInstantiator(cSynchronizedMap);
             = RuntimeEnv
                    .newInstantiator(cSynchronizedSortedMap);
             = RuntimeEnv.newInstantiator(cCheckedMap);
             = RuntimeEnv.newInstantiator(cCheckedSortedMap);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        .setAccessible(true);
        .setAccessible(true);
        .setAccessible(true);
        .setAccessible(true);
        .setAccessible(true);
        .setAccessible(true);
        .setAccessible(true);
    }
    private static Class<?> map(String classNameint id)
    {
        Class<?> clazz = RuntimeEnv.loadClass(className);
        .put(clazzid);
        return clazz;
    }
    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 ;
            default:
                return null;
        }
    }
    static int number(String name)
    {
        if (name.length() != 1)
            return 0;
        switch (name.charAt(0))
        {
            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 'w':
                return ;
            case 'z':
                return ;
            default:
                return 0;
        }
    }
    protected final Pipe.Schema<ObjectpipeSchema = new Pipe.Schema<Object>(
            this)
    {
        protected void transfer(Pipe pipeInput inputOutput output)
                throws IOException
        {
            transferObject(thispipeinputoutput);
        }
    };
    public PolymorphicMapSchema(IdStrategy strategy)
    {
        super(strategy);
    }
    public Pipe.Schema<ObjectgetPipeSchema()
    {
        return ;
    }
    public String getFieldName(int number)
    {
        return name(number);
    }
    public int getFieldNumber(String name)
    {
        return number(name);
    }
    public String messageFullName()
    {
        return Collection.class.getName();
    }
    public String messageName()
    {
        return Collection.class.getSimpleName();
    }
    public void mergeFrom(Input inputObject ownerthrows IOException
    {
        setValue(readObjectFrom(inputthisowner), owner);
    }
    public void writeTo(Output outputObject valuethrows IOException
    {
        writeObjectTo(outputvaluethis);
    }
    static int idFrom(Class<?> clazz)
    {
        final Integer id = .get(clazz);
        if (id == null)
            throw new RuntimeException("Unknown map: " + clazz);
        return id.intValue();
    }
    static Object instanceFrom(final int id)
    {
        switch (id)
        {
            case :
                return .;
            case :
                return .newInstance();
            case :
                return .newInstance();
            case :
                return .newInstance();
            case :
                return .newInstance();
            case :
                return .newInstance();
            case :
                return .newInstance();
            case :
                return .newInstance();
            default:
                throw new RuntimeException("Unknown id: " + id);
        }
    }
    @SuppressWarnings("unchecked")
    static void writeObjectTo(Output outputObject value,
            Schema<?> currentSchemaIdStrategy strategythrows IOException
    {
        if (Collections.class == value.getClass().getDeclaringClass())
        {
            writeNonPublicMapTo(outputvaluecurrentSchemastrategy);
            return;
        }
        Class<Objectclazz = (Class<Object>) value.getClass();
        if (EnumMap.class.isAssignableFrom(clazz))
        {
            strategy.writeEnumIdTo(output,
                    EnumIO.getKeyTypeFromEnumMap(value));
            // TODO use enum schema
        }
        else
        {
            strategy.writeMapIdTo(outputclazz);
        }
        if (output instanceof StatefulOutput)
        {
            // update using the derived schema.
            ((StatefulOutputoutput).updateLast(strategy.MAP_SCHEMA,
                    currentSchema);
        }
        strategy.MAP_SCHEMA.writeTo(output, (Map<ObjectObject>) value);
    }
    static void writeNonPublicMapTo(Output outputObject value,
            Schema<?> currentSchemaIdStrategy strategythrows IOException
    {
        final Integer n = .get(value.getClass());
        if (n == null)
            throw new RuntimeException("Unknown collection: "
                    + value.getClass());
        final int id = n.intValue();
        switch (id)
        {
            case :
                output.writeUInt32(id, 0, false);
                break;
            case :
            {
                final Object kv;
                try
                {
                    k = .get(value);
                    v = .get(value);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                output.writeUInt32(id, 0, false);
                if (k != null)
                    output.writeObject(1, kstrategy.OBJECT_SCHEMAfalse);
                if (v != null)
                    output.writeObject(3, vstrategy.OBJECT_SCHEMAfalse);
                break;
            }
            case :
                writeUnmodifiableMapTo(outputvaluecurrentSchemastrategyid);
                break;
            case :
                writeUnmodifiableMapTo(outputvaluecurrentSchemastrategyid);
                break;
            case :
                writeSynchronizedMapTo(outputvaluecurrentSchemastrategyid);
                break;
            case :
                writeSynchronizedMapTo(outputvaluecurrentSchemastrategyid);
                break;
            case :
                writeCheckedMapTo(outputvaluecurrentSchemastrategyid);
                break;
            case :
                writeCheckedMapTo(outputvaluecurrentSchemastrategyid);
                break;
            default:
                throw new RuntimeException("Should not happen.");
        }
    }
    private static void writeUnmodifiableMapTo(Output outputObject value,
            Schema<?> currentSchemaIdStrategy strategyint id)
            throws IOException
    {
        final Object m;
        try
        {
            m = .get(value);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        output.writeObject(idmstrategy.POLYMORPHIC_MAP_SCHEMAfalse);
    }
    private static void writeSynchronizedMapTo(Output outputObject value,
            Schema<?> currentSchemaIdStrategy strategyint id)
            throws IOException
    {
        final Object mmutex;
        try
        {
            m = .get(value);
            mutex = .get(value);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        if (mutex != value)
        {
            // TODO for future release, introduce an interface(GraphOutput) so
            // we
            // can check whether the output can retain references.
            throw new RuntimeException(
                    "This exception is thrown to fail fast. "
                            + "Synchronized collections with a different mutex would only "
                            + "work if graph format is used, since the reference is retained.");
        }
        output.writeObject(idmstrategy.POLYMORPHIC_MAP_SCHEMAfalse);
    }
    private static void writeCheckedMapTo(Output outputObject value,
            Schema<?> currentSchemaIdStrategy strategyint id)
            throws IOException
    {
        final Object mkeyTypevalueType;
        try
        {
            m = .get(value);
            keyType = .get(value);
            valueType = .get(value);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        output.writeObject(idmstrategy.POLYMORPHIC_MAP_SCHEMAfalse);
        output.writeObject(1, keyTypestrategy.CLASS_SCHEMAfalse);
        output.writeObject(2, valueTypestrategy.CLASS_SCHEMAfalse);
    }
    @SuppressWarnings("unchecked")
    static Object readObjectFrom(Input inputSchema<?> schemaObject owner,
            IdStrategy strategythrows IOException
    {
        final boolean graph = input instanceof GraphInput;
        Object ret = null;
        final int number = input.readFieldNumber(schema);
        switch (number)
        {
            case :
                if (graph)
                {
                    // update the actual reference.
                    ((GraphInputinput).updateLast(.owner);
                }
                if (0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
                ret = .;
                break;
            case :
            {
                final Object map = .newInstance();
                if (graph)
                {
                    // update the actual reference.
                    ((GraphInputinput).updateLast(mapowner);
                }
                if (0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
                return fillSingletonMapFrom(inputschemaownerstrategygraph,
                        map);
            }
            case :
                ret = readUnmodifiableMapFrom(inputschemaownerstrategy,
                        graph.newInstance(), false);
                break;
            case :
                ret = readUnmodifiableMapFrom(inputschemaownerstrategy,
                        graph.newInstance(), true);
                break;
            case :
                ret = readSynchronizedMapFrom(inputschemaownerstrategy,
                        graph.newInstance(), false);
                break;
            case :
                ret = readSynchronizedMapFrom(inputschemaownerstrategy,
                        graph.newInstance(), true);
                break;
            case :
                ret = readCheckedMapFrom(inputschemaownerstrategygraph,
                        .newInstance(), false);
                break;
            case :
                ret = readCheckedMapFrom(inputschemaownerstrategygraph,
                        .newInstance(), true);
                break;
            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 Map<ObjectObjectmap = strategy.resolveMapFrom(input)
                        .newMessage();
                if (input instanceof GraphInput)
                {
                    // update the actual reference.
                    ((GraphInputinput).updateLast(mapowner);
                }
                strategy.MAP_SCHEMA.mergeFrom(inputmap);
                return map;
            }
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        if (0 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
        return ret;
    }

    
Return true to
    private static Object fillSingletonMapFrom(Input inputSchema<?> schema,
            Object ownerIdStrategy strategyboolean graphObject map)
            throws IOException
    {
        switch (input.readFieldNumber(schema))
        {
            case 0:
                // both are null
                return map;
            case 1:
            {
                // key exists
                break;
            }
            case 3:
            {
                // key is null
                final Wrapper wrapper = new Wrapper();
                Object v = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
                if (!graph || !((GraphInputinput).isCurrentMessageReference())
                    v = wrapper.value;
                try
                {
                    .set(mapv);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                if (0 != input.readFieldNumber(schema))
                    throw new ProtostuffException("Corrupt input.");
                return map;
            }
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        final Wrapper wrapper = new Wrapper();
        Object k = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            k = wrapper.value;
        switch (input.readFieldNumber(schema))
        {
            case 0:
                // key exists but null value
                try
                {
                    .set(mapk);
                }
                catch (IllegalArgumentException e)
                {
                    throw new RuntimeException(e);
                }
                catch (IllegalAccessException e)
                {
                    throw new RuntimeException(e);
                }
                return map;
            case 3:
                // key and value exist
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        Object v = input.mergeObject(wrapperstrategy.OBJECT_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            v = wrapper.value;
        try
        {
            .set(mapk);
            .set(mapv);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        if (0 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
        return map;
    }
    private static Object readUnmodifiableMapFrom(Input input,
            Schema<?> schemaObject ownerIdStrategy strategyboolean graph,
            Object mapboolean smthrows IOException
    {
        if (graph)
        {
            // update the actual reference.
            ((GraphInputinput).updateLast(mapowner);
        }
        final Wrapper wrapper = new Wrapper();
        Object m = input.mergeObject(wrapperstrategy.POLYMORPHIC_MAP_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            m = wrapper.value;
        try
        {
            .set(mapm);
            if (sm)
                .set(mapm);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        return map;
    }
    private static Object readSynchronizedMapFrom(Input input,
            Schema<?> schemaObject ownerIdStrategy strategyboolean graph,
            Object mapboolean smthrows IOException
    {
        if (graph)
        {
            // update the actual reference.
            ((GraphInputinput).updateLast(mapowner);
        }
        final Wrapper wrapper = new Wrapper();
        Object m = input.mergeObject(wrapperstrategy.POLYMORPHIC_MAP_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            m = wrapper.value;
        try
        {
            .set(mapm);
            .set(mapmap);
            if (sm)
                .set(mapm);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        return map;
    }
    private static Object readCheckedMapFrom(Input inputSchema<?> schema,
            Object ownerIdStrategy strategyboolean graphObject map,
            boolean smthrows IOException
    {
        if (graph)
        {
            // update the actual reference.
            ((GraphInputinput).updateLast(mapowner);
        }
        final Wrapper wrapper = new Wrapper();
        Object m = input.mergeObject(wrapperstrategy.POLYMORPHIC_MAP_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            m = wrapper.value;
        if (1 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
        Object keyType = input.mergeObject(wrapperstrategy.CLASS_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            keyType = wrapper.value;
        if (2 != input.readFieldNumber(schema))
            throw new ProtostuffException("Corrupt input.");
        Object valueType = input.mergeObject(wrapperstrategy.CLASS_SCHEMA);
        if (!graph || !((GraphInputinput).isCurrentMessageReference())
            valueType = wrapper.value;
        try
        {
            .set(mapm);
            .set(mapkeyType);
            .set(mapvalueType);
            if (sm)
                .set(mapm);
        }
        catch (IllegalArgumentException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        return map;
    }
    static void transferObject(Pipe.Schema<ObjectpipeSchemaPipe pipe,
            Input inputOutput outputIdStrategy strategythrows IOException
    {
        final int number = input.readFieldNumber(pipeSchema.wrappedSchema);
        switch (number)
        {
            case :
                output.writeUInt32(numberinput.readUInt32(), false);
                break;
            case :
                if (0 != input.readUInt32())
                    throw new ProtostuffException("Corrupt input.");
                output.writeUInt32(number, 0, false);
                transferSingletonMap(pipeSchemapipeinputoutputstrategy);
                return;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                break;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                break;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                break;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                break;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                if (1 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
                output.writeObject(1, pipestrategy.CLASS_PIPE_SCHEMAfalse);
                if (2 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
                output.writeObject(2, pipestrategy.CLASS_PIPE_SCHEMAfalse);
                break;
            case :
                output.writeObject(numberpipe,
                        strategy.POLYMORPHIC_MAP_PIPE_SCHEMAfalse);
                if (1 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
                output.writeObject(1, pipestrategy.CLASS_PIPE_SCHEMAfalse);
                if (2 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
                output.writeObject(2, pipestrategy.CLASS_PIPE_SCHEMAfalse);
                break;
            case :
                strategy.transferEnumId(inputoutputnumber);
                if (output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutputoutput).updateLast(strategy.MAP_PIPE_SCHEMA,
                            pipeSchema);
                }
                Pipe.transferDirect(strategy.MAP_PIPE_SCHEMApipeinputoutput);
                return;
            case :
                strategy.transferMapId(inputoutputnumber);
                if (output instanceof StatefulOutput)
                {
                    // update using the derived schema.
                    ((StatefulOutputoutput).updateLast(strategy.MAP_PIPE_SCHEMA,
                            pipeSchema);
                }
                Pipe.transferDirect(strategy.MAP_PIPE_SCHEMApipeinputoutput);
                return;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
    }
    static void transferSingletonMap(Pipe.Schema<ObjectpipeSchemaPipe pipe,
            Input inputOutput outputIdStrategy strategythrows IOException
    {
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case 0:
                // both are null
                return;
            case 1:
            {
                // key exists
                break;
            }
            case 3:
            {
                // key is null
                output.writeObject(3, pipestrategy.OBJECT_PIPE_SCHEMAfalse);
                if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
                    throw new ProtostuffException("Corrupt input.");
                return;
            }
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        output.writeObject(1, pipestrategy.OBJECT_PIPE_SCHEMAfalse);
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case 0:
                // key exists but null value
                return;
            case 3:
                // key and value exist
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
        output.writeObject(3, pipestrategy.OBJECT_PIPE_SCHEMAfalse);
        if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
            throw new ProtostuffException("Corrupt input.");
    }
New to GrepCode? Check out our FAQ X