Search in sources :

Example 41 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project kogito-runtimes by kiegroup.

the class ProtostreamProtobufAdapterTypeProvider method buildMessageTypes.

private FileDescriptorProto buildMessageTypes(FileDescriptor descriptor) {
    FileDescriptorProto.Builder protoFileBuilder = FileDescriptorProto.newBuilder();
    protoFileBuilder.setPackage(descriptor.getPackage());
    protoFileBuilder.setName(descriptor.getName());
    for (Descriptor message : descriptor.getMessageTypes()) {
        protoFileBuilder.addMessageType(buildMessage(message));
    }
    return protoFileBuilder.build();
}
Also used : Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) EnumValueDescriptor(org.infinispan.protostream.descriptors.EnumValueDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto)

Example 42 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project kogito-runtimes by kiegroup.

the class ProtostreamProtobufAdapterTypeProviderTest method testFileDescriptorSortWithKogitoLastInOrigList.

@Test
void testFileDescriptorSortWithKogitoLastInOrigList() {
    ProtostreamProtobufAdapterTypeProvider prov = new ProtostreamProtobufAdapterTypeProvider();
    FileDescriptor fd1 = new FileDescriptor.Builder().withPackageName("kogito").build();
    FileDescriptor fd2 = new FileDescriptor.Builder().withPackageName("org.kie.kogito.app").build();
    List<FileDescriptor> fdCollectionKogitoOrder2 = Arrays.asList(fd2, fd1);
    List<FileDescriptor> fdCollectionSorted2 = prov.sortFds(fdCollectionKogitoOrder2);
    Assertions.assertThat(fdCollectionSorted2).hasSameElementsAs(fdCollectionKogitoOrder2);
    Assertions.assertThat(fdCollectionSorted2.get(0)).isEqualTo(fd1);
}
Also used : FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.jupiter.api.Test)

Example 43 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor in project kogito-runtimes by kiegroup.

the class AbstractMarshallerGenerator method javaTypeForMessage.

protected String javaTypeForMessage(FileDescriptor d, String messageName, SerializationContext serializationContext) {
    Map<String, FileDescriptor> descriptors = serializationContext.getFileDescriptors();
    for (Entry<String, FileDescriptor> entry : descriptors.entrySet()) {
        List<Descriptor> messages = entry.getValue().getMessageTypes();
        for (Descriptor msg : messages) {
            if (messageName.equals(msg.getName())) {
                return packageFromOption(d, msg) + "." + messageName;
            } else if (messageName.equals(msg.getFullName())) {
                return packageFromOption(d, msg) + "." + msg.getName();
            }
        }
        List<EnumDescriptor> enums = entry.getValue().getEnumTypes();
        for (EnumDescriptor msg : enums) {
            if (messageName.equals(msg.getName())) {
                return packageFromOption(d, msg) + "." + messageName;
            } else if (messageName.equals(msg.getFullName())) {
                return packageFromOption(d, msg) + "." + msg.getName();
            }
        }
    }
    return null;
}
Also used : FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor)

Aggregations

FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)43 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)24 Test (org.junit.Test)23 Descriptor (org.infinispan.protostream.descriptors.Descriptor)12 Configuration (org.infinispan.protostream.config.Configuration)11 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)11 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)11 List (java.util.List)8 SerializationContext (org.infinispan.protostream.SerializationContext)8 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)8 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 EntityIndexDescriptor (org.kie.kogito.persistence.api.schema.EntityIndexDescriptor)4 HashMap (java.util.HashMap)3 ResolutionContext (org.infinispan.protostream.descriptors.ResolutionContext)3 Ignore (org.junit.Ignore)3 Test (org.junit.jupiter.api.Test)3