use of org.infinispan.protostream.impl.SerializationContextImpl in project kogito-apps by kiegroup.
the class ProtoDomainModelProducerTest method getTestFileDescriptor.
static FileDescriptor getTestFileDescriptor() {
String content = TestUtils.getTestFileContent();
SerializationContext ctx = new SerializationContextImpl(Configuration.builder().build());
ctx.registerProtoFiles(FileDescriptorSource.fromString(DOMAIN_MODEL_PROTO_NAME, content));
return ctx.getFileDescriptors().get(DOMAIN_MODEL_PROTO_NAME);
}
use of org.infinispan.protostream.impl.SerializationContextImpl in project kogito-apps by kiegroup.
the class ProtoIndexParserTest method createFileDescriptor.
private FileDescriptor createFileDescriptor() {
SerializationContext ctx = new SerializationContextImpl(configureBuilder().build());
String content = getTestFileContent();
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test", content);
ctx.registerProtoFiles(fileDescriptorSource);
return ctx.getFileDescriptors().get("test");
}
use of org.infinispan.protostream.impl.SerializationContextImpl in project protostream by infinispan.
the class ProtobufUtil method write.
private static <A> void write(ImmutableSerializationContext ctx, TagWriterImpl out, A t) throws IOException {
if (t == null) {
throw new IllegalArgumentException("Object to marshall cannot be null");
}
BaseMarshallerDelegate marshallerDelegate = ((SerializationContextImpl) ctx).getMarshallerDelegate(t);
marshallerDelegate.marshall(out, null, t);
out.flush();
}
use of org.infinispan.protostream.impl.SerializationContextImpl in project protostream by infinispan.
the class WrappedMessage method readContainer.
private static Object readContainer(ImmutableSerializationContext ctx, TagReader in, int tag) throws IOException {
int containerSize = -1;
String containerTypeName = null;
Integer containerTypeId = null;
byte[] containerMessage = null;
int fieldCount = 0;
while (tag != 0) {
switch(tag) {
case WRAPPED_CONTAINER_SIZE << WireType.TAG_TYPE_NUM_BITS | WireType.WIRETYPE_VARINT:
containerSize = in.readInt32();
break;
case WRAPPED_CONTAINER_TYPE_NAME << WireType.TAG_TYPE_NUM_BITS | WireType.WIRETYPE_LENGTH_DELIMITED:
{
containerTypeName = in.readString();
break;
}
case WRAPPED_CONTAINER_TYPE_ID << WireType.TAG_TYPE_NUM_BITS | WireType.WIRETYPE_VARINT:
{
containerTypeId = mapTypeIdIn(in.readInt32(), ctx);
break;
}
case WRAPPED_CONTAINER_MESSAGE << WireType.TAG_TYPE_NUM_BITS | WireType.WIRETYPE_LENGTH_DELIMITED:
containerMessage = in.readByteArray();
break;
default:
throw new IllegalStateException("Unexpected tag : " + tag + " (Field number : " + WireType.getTagFieldNumber(tag) + ", Wire type : " + WireType.getTagWireType(tag) + ")");
}
if (++fieldCount == 3) {
break;
}
tag = in.readTag();
}
if (fieldCount != 3 || containerSize < 0 || containerMessage == null || containerTypeId == null && containerTypeName == null || containerTypeId != null && containerTypeName != null) {
throw new IOException("Invalid WrappedMessage encoding.");
}
if (containerTypeId != null) {
containerTypeName = ctx.getDescriptorByTypeId(containerTypeId).getFullName();
}
BaseMarshallerDelegate<?> marshallerDelegate = ((SerializationContextImpl) ctx).getMarshallerDelegate(containerTypeName);
BaseMarshaller<?> containerMarshaller = marshallerDelegate.getMarshaller();
if (!(containerMarshaller instanceof ElementContainerAdapter)) {
throw new IllegalStateException("The unmarshaller is not a container adapter : " + containerMarshaller.getJavaClass().getName());
}
TagReaderImpl nestedInput = TagReaderImpl.newNestedInstance((ProtobufTagMarshaller.ReadContext) in, containerMessage);
// pass the size to the marshaller of the container object
nestedInput.setParam(CONTAINER_SIZE_CONTEXT_PARAM, containerSize);
Object container = marshallerDelegate.unmarshall(nestedInput, null);
if (container == null) {
throw new IllegalStateException("The unmarshalled container must not be null");
}
containerMessage = null;
nestedInput = null;
if (containerMarshaller instanceof IterableElementContainerAdapter) {
IterableElementContainerAdapter adapter = (IterableElementContainerAdapter) containerMarshaller;
for (int i = 0; i < containerSize; i++) {
Object e = readMessage(ctx, in, true);
adapter.appendElement(container, e);
}
} else if (containerMarshaller instanceof IndexedElementContainerAdapter) {
IndexedElementContainerAdapter adapter = (IndexedElementContainerAdapter) containerMarshaller;
for (int i = 0; i < containerSize; i++) {
Object e = readMessage(ctx, in, true);
adapter.setElement(container, i, e);
}
} else {
throw new IllegalStateException("Unknown container adapter kind : " + containerMarshaller.getJavaClass().getName());
}
return container;
}
use of org.infinispan.protostream.impl.SerializationContextImpl in project kogito-runtimes by kiegroup.
the class ProtostreamProtobufAdapterTypeProvider method build.
// we transform protostream to protobuf descriptors
private List<com.google.protobuf.Descriptors.FileDescriptor> build() throws IOException, DescriptorValidationException {
SerializationContextImpl context = buildSerializationContext();
List<com.google.protobuf.Descriptors.FileDescriptor> protos = new ArrayList<>();
com.google.protobuf.Descriptors.FileDescriptor[] dependencies;
// make sure kogito-types is processed first or else will be missing as dependency for the application types
List<FileDescriptor> descriptorsSorted = sortFds(context.getFileDescriptors().values());
for (FileDescriptor entry : descriptorsSorted) {
dependencies = protos.toArray(new com.google.protobuf.Descriptors.FileDescriptor[protos.size()]);
protos.add(Descriptors.FileDescriptor.buildFrom(buildEnumTypes(entry), dependencies));
dependencies = protos.toArray(new com.google.protobuf.Descriptors.FileDescriptor[protos.size()]);
protos.add(Descriptors.FileDescriptor.buildFrom(buildMessageTypes(entry), dependencies));
}
return protos;
}
Aggregations