org.infinispan.protostream.annotations.impl.GeneratedMarshallerBase Maven / Gradle / Ivy
package org.infinispan.protostream.annotations.impl;
import java.io.IOException;
import org.infinispan.protostream.RawProtoStreamReader;
import org.infinispan.protostream.RawProtoStreamWriter;
import org.infinispan.protostream.impl.BaseMarshallerDelegate;
import org.infinispan.protostream.impl.ByteArrayOutputStreamEx;
import org.infinispan.protostream.impl.RawProtoStreamWriterImpl;
/**
* Base class for generated marshallers. Provides some handy helper methods.
*
* @author [email protected]
* @since 3.0
*/
public class GeneratedMarshallerBase {
/**
* Invoked by generated code.
*/
protected final T readMessage(BaseMarshallerDelegate marshallerDelegate, RawProtoStreamReader in) throws IOException {
return marshallerDelegate.unmarshall(null, null, in);
}
/**
* Invoked by generated code.
*/
protected final void writeMessage(BaseMarshallerDelegate marshallerDelegate, RawProtoStreamWriter out, T message) throws IOException {
if (message == null) {
throw new IllegalArgumentException("Object to marshall cannot be null");
}
marshallerDelegate.marshall(null, message, null, out);
out.flush();
}
/**
* Invoked by generated code.
*/
protected final void writeNestedMessage(BaseMarshallerDelegate marshallerDelegate, RawProtoStreamWriter out, int fieldNumber, T message) throws IOException {
ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx();
RawProtoStreamWriter nested = RawProtoStreamWriterImpl.newInstance(baos);
writeMessage(marshallerDelegate, nested, message);
out.writeBytes(fieldNumber, baos.getByteBuffer());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy