Search in sources :

Example 1 with ByteBufferOutputStream

use of org.wildfly.clustering.marshalling.spi.ByteBufferOutputStream in project wildfly by wildfly.

the class DefaultProtoStreamWriter method writeObjectNoTag.

@Override
public void writeObjectNoTag(Object value) throws IOException {
    ImmutableSerializationContext context = this.getSerializationContext();
    ProtoStreamMarshaller<Object> marshaller = this.findMarshaller(value.getClass());
    OptionalInt size = this.size(marshaller, value);
    try (ByteBufferOutputStream output = new ByteBufferOutputStream(size)) {
        TagWriterImpl writer = size.isPresent() ? TagWriterImpl.newInstance(context, output, size.getAsInt()) : TagWriterImpl.newInstance(context, output);
        marshaller.writeTo(new DefaultProtoStreamWriter(writer), value);
        writer.flush();
        ByteBuffer buffer = output.getBuffer();
        int offset = buffer.arrayOffset();
        int length = buffer.limit() - offset;
        this.writeVarint32(length);
        this.writeRawBytes(buffer.array(), offset, length);
    }
}
Also used : ByteBufferOutputStream(org.wildfly.clustering.marshalling.spi.ByteBufferOutputStream) ImmutableSerializationContext(org.infinispan.protostream.ImmutableSerializationContext) OptionalInt(java.util.OptionalInt) TagWriterImpl(org.infinispan.protostream.impl.TagWriterImpl) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 OptionalInt (java.util.OptionalInt)1 ImmutableSerializationContext (org.infinispan.protostream.ImmutableSerializationContext)1 TagWriterImpl (org.infinispan.protostream.impl.TagWriterImpl)1 ByteBufferOutputStream (org.wildfly.clustering.marshalling.spi.ByteBufferOutputStream)1