Java Code Examples for io.protostuff.Output#writeObject()

The following examples show how to use io.protostuff.Output#writeObject() . 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: PolymorphicCollectionSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
private static void writeCheckedCollectionTo(Output output, Object value,
        Schema<?> currentSchema, IdStrategy strategy, int id)
        throws IOException
{
    final Object c, type;
    try
    {
        c = fCheckedCollection_c.get(value);
        type = fCheckedCollection_type.get(value);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }

    output.writeObject(id, c, strategy.POLYMORPHIC_COLLECTION_SCHEMA, false);
    output.writeObject(1, type, strategy.CLASS_SCHEMA, false);
}
 
Example 2
Source File: PolymorphicCollectionSchema.java    From protostuff with Apache License 2.0 6 votes vote down vote up
private static void writeUnmodifiableCollectionTo(Output output,
        Object value, Schema<?> currentSchema, IdStrategy strategy, int id)
        throws IOException
{
    final Object c;
    try
    {
        c = fUnmodifiableCollection_c.get(value);
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }

    output.writeObject(id, c, strategy.POLYMORPHIC_COLLECTION_SCHEMA, false);
}
 
Example 3
Source File: ArraySchemas.java    From protostuff with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(Output output, Object message) throws IOException
{
    final Object[] array = (Object[])message;
    final int len = array.length;

    output.writeInt32(ID_ARRAY_LEN, len, false);

    int nullCount = 0;
    for (int i = 0; i < len; i++)
    {
        Object v = array[i];
        if (v != null)
        {
            if (nullCount != 0)
            {
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                nullCount = 0;
            }

            output.writeObject(ID_ARRAY_DATA, v, hs.getSchema(), true);
        }
        else if (allowNullArrayElement)
        {
            nullCount++;
        }
    }

    // if last element is null
    if (nullCount != 0)
        output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
}
 
Example 4
Source File: MapReduceInfoResponseList.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, MapReduceInfoResponseList message) throws IOException {
    
    if (message.getResults() != null) {
        for (MapReduceInfoResponse response : message.getResults()) {
            if (null != response) {
                output.writeObject(1, response, MapReduceInfoResponse.getSchema(), true);
            }
        }
    }
    
    output.writeUInt64(2, message.getOperationTimeMS(), false);
    
    List<String> messages = message.getMessages();
    if (messages != null) {
        for (String msg : messages) {
            if (msg != null)
                output.writeString(3, msg, true);
        }
    }
    
    List<QueryExceptionType> exceptions = message.getExceptions();
    if (exceptions != null) {
        for (QueryExceptionType exception : exceptions) {
            if (exception != null)
                output.writeObject(4, exception, QueryExceptionType.getSchema(), true);
        }
    }
    
}
 
Example 5
Source File: BulkResultsInfoResponse.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, BulkResultsInfoResponse message) throws IOException {
    
    if (message.user != null) {
        output.writeString(1, message.user, false);
    }
    
    if (message.bulkResultsId != null) {
        output.writeString(2, message.bulkResultsId, false);
    }
    
    if (message.jobDirectory != null) {
        output.writeString(3, message.jobDirectory, false);
    }
    
    if (message.outputDestination != null) {
        output.writeString(4, message.outputDestination, false);
    }
    
    if (message.configuration != null) {
        output.writeString(5, message.configuration, false);
    }
    
    if (message.queryId != null) {
        output.writeString(6, message.queryId, false);
    }
    
    if (message.serializationFormat != null) {
        output.writeString(7, message.serializationFormat, false);
    }
    
    if (message.jobs != null) {
        for (Job job : message.jobs) {
            if (job != null)
                output.writeObject(6, job, Job.getSchema(), true);
        }
    }
}
 
Example 6
Source File: BulkResultsInfoResponse.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, Job message) throws IOException {
    if (message.getJobId() != null) {
        output.writeString(1, message.getJobId(), false);
    }
    
    if (message.history != null) {
        for (History h : message.history) {
            if (h != null)
                output.writeObject(2, h, History.getSchema(), true);
        }
    }
}
 
Example 7
Source File: BulkResultsInfoResponseList.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, BulkResultsInfoResponseList message) throws IOException {
    
    if (message.getQueryId() != null) {
        output.writeString(1, message.getQueryId(), false);
    }
    
    if (message.getLogicName() != null) {
        output.writeString(2, message.getLogicName(), false);
    }
    
    output.writeUInt64(3, message.getOperationTimeMS(), false);
    
    List<String> messages = message.getMessages();
    if (messages != null) {
        for (String msg : messages) {
            if (msg != null)
                output.writeString(4, msg, true);
        }
    }
    
    List<QueryExceptionType> exceptions = message.getExceptions();
    if (exceptions != null) {
        for (QueryExceptionType exception : exceptions) {
            if (exception != null)
                output.writeObject(5, exception, QueryExceptionType.getSchema(), true);
        }
    }
    
    if (message.bulkResults != null) {
        for (BulkResultsInfoResponse result : message.bulkResults) {
            if (result != null)
                output.writeObject(6, result, BulkResultsInfoResponse.getSchema(), true);
        }
    }
}
 
Example 8
Source File: DefaultFacets.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, DefaultFacets message) throws IOException {
    if (message.fields != null) {
        for (FieldCardinalityBase field : message.fields) {
            if (field != null)
                output.writeObject(1, (DefaultFieldCardinality) field, DefaultFieldCardinality.getSchema(), true);
        }
    }
}
 
Example 9
Source File: DefaultField.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(Output output, DefaultField message) throws IOException {
    if (message.markings != null)
        output.writeObject(1, message.markings, MapSchema.SCHEMA, false);
    if (message.columnVisibility != null)
        output.writeString(2, message.columnVisibility, false);
    output.writeUInt64(3, message.timestamp, false);
    if (message.name != null)
        output.writeString(4, message.name, false);
    if (message.value != null)
        output.writeObject(5, message.value, message.value.cachedSchema(), false);
}
 
Example 10
Source File: SimpleEvent.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void writeTo(Output output, SimpleEvent message) throws IOException {
    if (message.metadata != null) {
        output.writeObject(1, message.metadata, Metadata.getSchema(), false);
    }
    
    if (message.fields != null) {
        for (SimpleField field : message.fields) {
            if (field != null)
                output.writeObject(2, field, SimpleField.getSchema(), true);
        }
    }
    if (message.markings != null) {
        output.writeObject(3, message.markings, MapSchema.SCHEMA, false);
    }
}
 
Example 11
Source File: ZonedDateTimeSchema.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(final Output output, final ZonedDateTime message) throws IOException {
    output.writeObject(1, message.toLocalDateTime(), LocalDateTimeSchema.INSTANCE, false);
    output.writeObject(2, message.getOffset(), ZoneOffsetSchema.INSTANCE, false);
    if (message.getZone() != null) {
        output.writeObject(3, message.getZone(), ZoneIdSchema.INSTANCE, false);
    }
}
 
Example 12
Source File: AbstractRuntimeObjectSchemaTest.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
protected void transferValue(Pipe pipe, Input input, Output output, int number, boolean repeated)
    throws IOException
{
    output.writeObject(number, pipe, HS.getPipeSchema(), repeated);
}
 
Example 13
Source File: IndexStatsResponse.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(Output output, IndexStatsResponse message) throws IOException {
    for (FieldStat fs : message.fieldStats) {
        output.writeObject(1, fs, FieldStat.SCHEMA, true);
    }
}
 
Example 14
Source File: AbstractRuntimeObjectSchemaTest.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(Output output, int number, AbstractCollection<T> value, boolean repeated) throws IOException
{
    output.writeObject(number, value, schema, repeated);
}
 
Example 15
Source File: AbstractRuntimeObjectSchemaTest.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(Output output, int number, AbstractCollection<T> value, boolean repeated) throws IOException
{
    output.writeObject(number, value, schema, repeated);
}
 
Example 16
Source File: PolymorphicMapSchema.java    From protostuff with Apache License 2.0 4 votes vote down vote up
static void transferSingletonMap(Pipe.Schema<Object> pipeSchema, Pipe pipe,
        Input input, Output output, IdStrategy strategy) throws 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, pipe, strategy.OBJECT_PIPE_SCHEMA, false);

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

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

    output.writeObject(1, pipe, strategy.OBJECT_PIPE_SCHEMA, false);

    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, pipe, strategy.OBJECT_PIPE_SCHEMA, false);

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
Example 17
Source File: AbstractRuntimeObjectSchemaTest.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
public void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated) throws IOException
{
    output.writeObject(number, pipe, schema.pipeSchema, repeated);
}
 
Example 18
Source File: OffsetTimeSchema.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(final Output output, final OffsetTime message) throws IOException {
    output.writeObject(1, message.toLocalTime(), LocalTimeSchema.INSTANCE, false);
    output.writeObject(2, message.getOffset(), ZoneOffsetSchema.INSTANCE, false);
}
 
Example 19
Source File: PolymorphicMapSchema.java    From protostuff with Apache License 2.0 4 votes vote down vote up
static void transferObject(Pipe.Schema<Object> pipeSchema, Pipe pipe,
        Input input, Output output, IdStrategy strategy, 
        final int number) throws IOException
{
    switch (number)
    {
        case ID_EMPTY_MAP:
            output.writeUInt32(number, input.readUInt32(), false);
            break;

        case ID_SINGLETON_MAP:
            if (0 != input.readUInt32())
                throw new ProtostuffException("Corrupt input.");

            output.writeUInt32(number, 0, false);

            transferSingletonMap(pipeSchema, pipe, input, output, strategy);
            return;

        case ID_UNMODIFIABLE_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);
            break;

        case ID_UNMODIFIABLE_SORTED_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);
            break;

        case ID_SYNCHRONIZED_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);
            break;

        case ID_SYNCHRONIZED_SORTED_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);
            break;

        case ID_CHECKED_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);

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

            output.writeObject(1, pipe, strategy.CLASS_PIPE_SCHEMA, false);

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

            output.writeObject(2, pipe, strategy.CLASS_PIPE_SCHEMA, false);
            break;

        case ID_CHECKED_SORTED_MAP:
            output.writeObject(number, pipe,
                    strategy.POLYMORPHIC_MAP_PIPE_SCHEMA, false);

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

            output.writeObject(1, pipe, strategy.CLASS_PIPE_SCHEMA, false);

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

            output.writeObject(2, pipe, strategy.CLASS_PIPE_SCHEMA, false);
            break;

        case ID_ENUM_MAP:
            strategy.transferEnumId(input, output, number);

            if (output instanceof StatefulOutput)
            {
                // update using the derived schema.
                ((StatefulOutput) output).updateLast(strategy.MAP_PIPE_SCHEMA,
                        pipeSchema);
            }

            Pipe.transferDirect(strategy.MAP_PIPE_SCHEMA, pipe, input, output);
            return;
        case ID_MAP:
            strategy.transferMapId(input, output, number);

            if (output instanceof StatefulOutput)
            {
                // update using the derived schema.
                ((StatefulOutput) output).updateLast(strategy.MAP_PIPE_SCHEMA,
                        pipeSchema);
            }

            Pipe.transferDirect(strategy.MAP_PIPE_SCHEMA, pipe, input, output);
            return;

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

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
Example 20
Source File: OffsetDateTimeSchema.java    From joyrpc with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(final Output output, final OffsetDateTime message) throws IOException {
    output.writeObject(1, message.toLocalDateTime(), LocalDateTimeSchema.INSTANCE, false);
    output.writeObject(2, message.getOffset(), ZoneOffsetSchema.INSTANCE, false);
}