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

The following examples show how to use io.protostuff.Output#writeBytes() . 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: NioBufInput.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public void transferByteRangeTo(Output output, boolean utf8String, int fieldNumber, boolean repeated)
                                                                                                     throws IOException {
    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (utf8String) {
        // if it is a UTF string, we have to call the writeByteRange.

        if (nioBuffer.hasArray()) {
            output.writeByteRange(true, fieldNumber, nioBuffer.array(),
                nioBuffer.arrayOffset() + nioBuffer.position(), length, repeated);
            nioBuffer.position(nioBuffer.position() + length);
        } else {
            byte[] bytes = new byte[length];
            nioBuffer.get(bytes);
            output.writeByteRange(true, fieldNumber, bytes, 0, bytes.length, repeated);
        }
    } else {
        // Do the potentially vastly more efficient potential splice call.
        if (nioBuffer.remaining() < length) {
            throw ProtocolException.misreportedSize();
        }

        ByteBuffer dup = nioBuffer.slice();
        dup.limit(length);

        output.writeBytes(fieldNumber, dup, repeated);

        nioBuffer.position(nioBuffer.position() + length);
    }
}
 
Example 2
Source File: NioBufInput.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public void transferByteRangeTo(Output output, boolean utf8String, int fieldNumber,
                                boolean repeated) throws IOException {
    final int length = readRawVarInt32();
    if (length < 0) {
        throw ProtocolException.negativeSize();
    }

    if (utf8String) {
        // if it is a UTF string, we have to call the writeByteRange.

        if (nioBuffer.hasArray()) {
            output.writeByteRange(true, fieldNumber, nioBuffer.array(),
                    nioBuffer.arrayOffset() + nioBuffer.position(), length, repeated);
            nioBuffer.position(nioBuffer.position() + length);
        } else {
            byte[] bytes = new byte[length];
            nioBuffer.get(bytes);
            output.writeByteRange(true, fieldNumber, bytes, 0, bytes.length, repeated);
        }
    } else {
        // Do the potentially vastly more efficient potential splice call.
        if (nioBuffer.remaining() < length) {
            throw ProtocolException.misreportedSize();
        }

        ByteBuffer dup = nioBuffer.slice();
        dup.limit(length);

        output.writeBytes(fieldNumber, dup, repeated);

        nioBuffer.position(nioBuffer.position() + length);
    }
}
 
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 value) throws IOException
{
    ByteString[] array = (ByteString[]) value;
    output.writeInt32(ID_ARRAY_LEN, array.length, false);

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

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

    // if last element is null
    if (nullCount != 0)
        output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
}
 
Example 4
Source File: RuntimeUnsafeFieldFactory.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(Output output, int number, ByteString value,
        boolean repeated) throws IOException
{
    output.writeBytes(number, value, repeated);
}
 
Example 5
Source File: RuntimeReflectionFieldFactory.java    From protostuff with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(Output output, int number, ByteString value,
        boolean repeated) throws IOException
{
    output.writeBytes(number, value, repeated);
}