Java Code Examples for io.protostuff.Input#readUInt32()

The following examples show how to use io.protostuff.Input#readUInt32() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
static Class<?> getArrayClass(Input input, Schema<?> schema,
        final Class<?> componentType) throws IOException
{
    if (input.readFieldNumber(schema) != ID_ARRAY_DIMENSION)
        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(componentType, arg).getClass();
}
 
Example 2
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 6 votes vote down vote up
protected Object readPrimitiveFrom(Input input, Object owner, int len)
        throws IOException
{
    short[] array = new short[len];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len; i++)
    {
        if (ID_ARRAY_DATA != input.readFieldNumber(this))
            throw new ProtostuffException("Corrupt input.");

        array[i] = (short) input.readUInt32();
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 3
Source File: IncrementalIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws IOException
{
    final int id = input.readUInt32();

    final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null;
    if (wrapper == null)
        throw new UnknownTypeException("unknown pojo id: " + id);

    return wrapper;
}
 
Example 4
Source File: IncrementalIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws IOException
{
    final int id = input.readUInt32();

    final RegisteredDelegate<T> rd = id < delegates.size() ?
            (RegisteredDelegate<T>) delegates.get(id) : null;
    if (rd == null)
        throw new UnknownTypeException("delegate id: " + id + " (Outdated registry)");

    return rd;
}
 
Example 5
Source File: ExplicitIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws IOException
{
    final int id = input.readUInt32();

    final RegisteredDelegate<T> rd = id < delegates.size() ?
            (RegisteredDelegate<T>) delegates.get(id) : null;
    if (rd == null)
        throw new UnknownTypeException("delegate id: " + id + " (Outdated registry)");

    return rd;
}
 
Example 6
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Object readFrom(Input input, Object owner) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();

    Object[] array = (Object[])Array.newInstance(delegate.typeClass(), len);
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = delegate.readFrom(input);
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 7
Source File: IncrementalIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
protected MapSchema.MessageFactory resolveMapFrom(Input input)
        throws IOException
{
    final int id = input.readUInt32();

    final RuntimeMapFactory factory = id < maps.size() ? maps.get(id) : null;
    if (factory == null)
        throw new UnknownTypeException("Unknown map id: " + id);

    return factory;
}
 
Example 8
Source File: ExplicitIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
protected MapSchema.MessageFactory resolveMapFrom(Input input)
        throws IOException
{
    final int id = input.readUInt32();

    final MapSchema.MessageFactory factory = id < maps.size() ? maps.get(id) : null;
    if (factory == null)
        throw new UnknownTypeException("map id: " + id + " (Outdated registry)");

    return factory;
}
 
Example 9
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
protected void transfer(Pipe pipe, Input input, Output output)
        throws IOException
{
    if (ID_ARRAY_LEN != input
            .readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();
    // write it back
    output.writeInt32(ID_ARRAY_LEN, len, false);

    for (int i = 0, nullCount = 0; i < len;)
    {
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case ID_ARRAY_DATA:
                i++;
                output.writeObject(ID_ARRAY_DATA, pipe, hs.getPipeSchema(),
                        true);
                break;
            case ID_ARRAY_NULLCOUNT:
                nullCount = input.readUInt32();
                i += nullCount;
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
Example 10
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Object readFrom(Input input, Object owner) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();

    byte[][] array = new byte[len][];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = input.readByteArray();
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 11
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Object readFrom(Input input, Object owner) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();

    ByteString[] array = new ByteString[len];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = input.readBytes();
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 12
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Object readFrom(Input input, Object owner) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();

    String[] array = new String[len];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = input.readString();
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 13
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Object readFrom(Input input, Object owner) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();

    Object[] array = (Object[])Array.newInstance(hs.getSchema().typeClass(), len);
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = input.mergeObject(null, hs.getSchema());
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 14
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
protected Object readBoxedFrom(Input input, Object owner, int len)
        throws IOException
{
    final Float[] array = new Float[len];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = input.readFloat();
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 15
Source File: IncrementalIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber)
        throws IOException
{
    final int id = input.readUInt32();

    final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null;
    if (wrapper == null)
        throw new UnknownTypeException("unknown pojo id: " + id);

    output.writeUInt32(fieldNumber, id, false);

    return wrapper;
}
 
Example 16
Source File: SampleDelegates.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public Singleton readFrom(Input input) throws IOException
{
    if (0 != input.readUInt32())
        throw new ProtostuffException("Corrupt input.");

    return Singleton.INSTANCE;
}
 
Example 17
Source File: IncrementalIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
protected EnumIO<?> resolveEnumFrom(Input input) throws IOException
{
    final int id = input.readUInt32();

    final RuntimeEnumIO reio = id < enums.size() ? enums.get(id) : null;
    if (reio == null)
        throw new UnknownTypeException("Unknown enum id: " + id);

    return reio.eio;
}
 
Example 18
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
protected Object readBoxedFrom(Input input, Object owner, int len)
        throws IOException
{
    final Character[] array = new Character[len];
    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(array, owner);
    }

    for (int i = 0; i < len;)
    {
        switch (input.readFieldNumber(this))
        {
            case ID_ARRAY_DATA:
                array[i++] = (char) input.readUInt32();
                break;
            case ID_ARRAY_NULLCOUNT:
                i += input.readUInt32();
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(this))
        throw new ProtostuffException("Corrupt input.");

    return array;
}
 
Example 19
Source File: ExplicitIdStrategy.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber)
        throws IOException
{
    final int id = input.readUInt32();

    final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null;
    if (wrapper == null)
        throw new UnknownTypeException("pojo id: " + id + " (Outdated registry)");

    return wrapper;
}
 
Example 20
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
static void transferObject(Pipe.Schema<Object> pipeSchema, Pipe pipe,
        Input input, Output output, IdStrategy strategy,
        Delegate<?> delegate) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");

    int len = input.readInt32();
    // write it back
    output.writeInt32(ID_ARRAY_LEN, len, false);
    
    // if from derived schema and the array is boxed, the length written
    // during serialization is: -(len + 1)
    if (len < 0)
        len = -len - 1;

    for (int i = 0, nullCount = 0; i < len;)
    {
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case ID_ARRAY_DATA:
                i++;
                delegate.transfer(pipe, input, output, ID_ARRAY_DATA, true);
                break;
            case ID_ARRAY_NULLCOUNT:
                nullCount = input.readUInt32();
                i += nullCount;
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}