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

The following examples show how to use io.protostuff.Input#readFieldNumber() . 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: DefaultMetadataQueryResponse.java    From datawave with Apache License 2.0 6 votes vote down vote up
public void mergeFrom(Input input, DefaultMetadataQueryResponse message) throws IOException {
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                message.setTotalResults(input.readUInt64());
            case 2:
                if (message.fields == null) {
                    message.fields = new ArrayList<MetadataFieldBase>();
                }
                
                message.fields.add(input.mergeObject(null, DefaultMetadataField.getSchema()));
                break;
            default:
                input.handleUnknownField(number, this);
                break;
        }
    }
}
 
Example 2
Source File: ObjectSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
static ArrayWrapper newArrayWrapper(Input input, Schema<?> schema,
        boolean mapped, IdStrategy strategy) throws IOException
{
    final Class<?> componentType = strategy.resolveArrayComponentTypeFrom(
            input, mapped);

    if (input.readFieldNumber(schema) != ID_ARRAY_LEN)
        throw new ProtostuffException("Corrupt input.");
    final int len = input.readUInt32();

    if (input.readFieldNumber(schema) != ID_ARRAY_DIMENSION)
        throw new ProtostuffException("Corrupt input.");
    final int dimensions = input.readUInt32();

    if (dimensions == 1)
        return new ArrayWrapper(Array.newInstance(componentType, len));

    final int[] arg = new int[dimensions];
    arg[0] = len;
    return new ArrayWrapper(Array.newInstance(componentType, arg));
}
 
Example 3
Source File: LocalDateSchema.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
@Override
public void mergeFrom(final Input input, final LocalDate message) throws IOException {
    while (true) {
        int number = input.readFieldNumber(this);
        switch (number) {
            case 0:
                return;
            case 1:
                setValue(FIELD_YEAR, message, input.readInt32());
                break;
            case 2:
                setValue(FIELD_MONTH, message, (short) input.readInt32());
                break;
            case 3:
                setValue(FIELD_DAY, message, (short) input.readInt32());
                break;
            default:
                input.handleUnknownField(number, this);
        }
    }
}
 
Example 4
Source File: PolymorphicEnumSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
static void transferObject(Pipe.Schema<Object> pipeSchema, Pipe pipe,
        Input input, Output output, IdStrategy strategy) throws IOException
{
    if (ID_ENUM != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");

    strategy.transferEnumId(input, output, ID_ENUM);

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

    EnumIO.transfer(pipe, input, output, 1, false, strategy);

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
Example 5
Source File: InstantSchema.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
@Override
public void mergeFrom(final Input input, final Instant message) throws IOException {
    while (true) {
        int number = input.readFieldNumber(this);
        switch (number) {
            case 0:
                return;
            case 1:
                setValue(FIELD_SECONDS, message, input.readInt64());
                break;
            case 2:
                setValue(FIELD_NANOS, message, input.readInt32());
                break;
            default:
                input.handleUnknownField(number, this);
        }
    }
}
 
Example 6
Source File: RuntimeSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
@Override
public final void mergeFrom(Input input, T message) throws IOException
{
    for (int n = input.readFieldNumber(this); n != 0; n = input.readFieldNumber(this))
    {
        final Field<T> field = getFieldByNumber(n);
        if (field == null)
        {
            input.handleUnknownField(n, this);
        }
        else
        {
            field.mergeFrom(input, message);
        }
    }
}
 
Example 7
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 8
Source File: BulkResultsInfoResponse.java    From datawave with Apache License 2.0 6 votes vote down vote up
public void mergeFrom(Input input, Job message) throws IOException {
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                message.setJobId(input.readString());
                break;
            case 2:
                if (message.history == null)
                    message.history = new TreeSet<History>();
                message.history.add(input.mergeObject(null, History.getSchema()));
                break;
            default:
                input.handleUnknownField(number, this);
                break;
        }
    }
}
 
Example 9
Source File: ClassSchema.java    From protostuff with Apache License 2.0 5 votes vote down vote up
static Object readObjectFrom(Input input, Schema<?> schema, Object owner,
        IdStrategy strategy) throws IOException
{
    final int number = input.readFieldNumber(schema);
    final Object value;
    switch (number)
    {
        case ID_CLASS:
            value = strategy.resolveClassFrom(input, false, false);
            break;

        case ID_CLASS_MAPPED:
            value = strategy.resolveClassFrom(input, true, false);
            break;

        case ID_CLASS_ARRAY:
            value = ObjectSchema.getArrayClass(input, schema,
                    strategy.resolveClassFrom(input, false, true));
            break;

        case ID_CLASS_ARRAY_MAPPED:
            value = ObjectSchema.getArrayClass(input, schema,
                    strategy.resolveClassFrom(input, true, true));
            break;

        default:
            throw new ProtostuffException("Corrupt input.");
    }

    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(value, owner);
    }

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

    return value;
}
 
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();

    Object[] array = (Object[])Array.newInstance(eio.enumClass, 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++] = eio.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 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();

    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 12
Source File: IndexStatsResponse.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void mergeFrom(Input input, IndexStatsResponse other) throws IOException {
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                other.fieldStats.add(input.mergeObject(null, FieldStat.SCHEMA));
            default:
                input.handleUnknownField(number, SCHEMA);
        }
    }
}
 
Example 13
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 Short[] array = new Short[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++] = (short) 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 14
Source File: DefaultField.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void mergeFrom(Input input, DefaultField message) throws IOException {
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                message.markings = new HashMap<String,String>();
                input.mergeObject(message.markings, MapSchema.SCHEMA);
                break;
            case 2:
                message.columnVisibility = input.readString();
                break;
            case 3:
                message.timestamp = input.readUInt64();
                break;
            case 4:
                message.name = input.readString();
                break;
            case 5:
                message.value = input.mergeObject(null, TypedValue.getSchema());
                break;
            default:
                input.handleUnknownField(number, this);
                break;
        }
    }
}
 
Example 15
Source File: DerivativeSchema.java    From protostuff with Apache License 2.0 5 votes vote down vote up
/**
 * Delegates to the schema derived from the input. The {@code owner} owns the message (polymorphic) that is tied to
 * this schema.
 */
@Override
public void mergeFrom(Input input, final Object owner) throws IOException
{
    final int first = input.readFieldNumber(this);
    if (first != ID_POJO)
        throw new ProtostuffException("order not preserved.");

    doMergeFrom(input,
            strategy.resolvePojoFrom(input, ID_POJO).getSchema(), owner);
}
 
Example 16
Source File: BulkResultsInfoResponse.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void mergeFrom(Input input, BulkResultsInfoResponse message) throws IOException {
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                message.setUser(input.readString());
                break;
            case 2:
                message.setBulkResultsId(input.readString());
                break;
            case 3:
                message.setJobDirectory(input.readString());
                break;
            case 4:
                message.setOutputDestination(input.readString());
                break;
            case 5:
                message.setConfiguration(input.readString());
                break;
            case 6:
                message.setQueryId(input.readString());
                break;
            case 7:
                message.setSerializationFormat(input.readString());
                break;
            case 8:
                if (message.jobs == null)
                    message.jobs = new ArrayList<Job>();
                message.jobs.add(input.mergeObject(null, Job.getSchema()));
                break;
            default:
                input.handleUnknownField(number, this);
                break;
        }
    }
}
 
Example 17
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();
    return primitive ? readPrimitiveFrom(input, owner, len) : 
            readBoxedFrom(input, owner, len);
}
 
Example 18
Source File: ClassSchema.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) throws IOException
{
    final int number = input.readFieldNumber(pipeSchema.wrappedSchema);
    switch (number)
    {
        case ID_CLASS:
            ObjectSchema.transferClass(pipe, input, output, number, pipeSchema,
                    false, false, strategy);
            break;

        case ID_CLASS_MAPPED:
            ObjectSchema.transferClass(pipe, input, output, number, pipeSchema,
                    true, false, strategy);
            break;

        case ID_CLASS_ARRAY:
            ObjectSchema.transferClass(pipe, input, output, number, pipeSchema,
                    false, true, strategy);
            break;

        case ID_CLASS_ARRAY_MAPPED:
            ObjectSchema.transferClass(pipe, input, output, number, pipeSchema,
                    true, true, strategy);
            break;

        default:
            throw new ProtostuffException("Corrupt input.");
    }

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
Example 19
Source File: FileResponseList.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void mergeFrom(Input input, FileResponseList message) throws IOException {
    List<FileDetails> files = null;
    LinkedList<QueryExceptionType> exceptions = null;
    int number;
    while ((number = input.readFieldNumber(this)) != 0) {
        switch (number) {
            case 1:
                if (files == null)
                    files = new ArrayList<FileDetails>();
                files.add(input.mergeObject(null, FileDetails.getSchema()));
                break;
            case 2:
                message.setOperationTimeMS(input.readUInt64());
                break;
            case 3:
                message.addMessage(input.readString());
                break;
            case 4:
                if (exceptions == null)
                    exceptions = new LinkedList<QueryExceptionType>();
                exceptions.add(input.mergeObject(null, QueryExceptionType.getSchema()));
                break;
            default:
                input.handleUnknownField(number, this);
                break;
        }
    }
    if (exceptions != null)
        message.setExceptions(exceptions);
    if (files != null)
        message.setFiles(files);
}
 
Example 20
Source File: ArraySchema.java    From protostuff with Apache License 2.0 5 votes vote down vote up
static Object readObjectFrom(Input input, Schema<?> schema, Object owner,
        IdStrategy strategy) throws IOException
{
    final int number = input.readFieldNumber(schema);
    final boolean mapped;
    switch (number)
    {
        case ID_ARRAY:
            mapped = false;
            break;

        case ID_ARRAY_MAPPED:
            mapped = true;
            break;

        default:
            throw new ProtostuffException("Corrupt input.");
    }

    final ArrayWrapper mArrayWrapper = ObjectSchema.newArrayWrapper(input,
            schema, mapped, strategy);

    if (input instanceof GraphInput)
    {
        // update the actual reference.
        ((GraphInput) input).updateLast(mArrayWrapper.array, owner);
    }

    strategy.COLLECTION_SCHEMA.mergeFrom(input, mArrayWrapper);

    return mArrayWrapper.array;
}