org.infinispan.protostream.FileDescriptorSource Java Examples

The following examples show how to use org.infinispan.protostream.FileDescriptorSource. 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: HotRodSearchClient.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
private void registerProto(boolean reset, String... protoKeys) {
    RemoteCache<Object, Object> cache = manager.getCache(PROTO_CACHE);
    if (cache == null) {
        throw new IllegalStateException(String.format("Missing %s cache!", PROTO_CACHE));
    }

    SerializationContext ctx = MarshallerUtil.getSerializationContext(manager);
    FileDescriptorSource fds = new FileDescriptorSource();
    for (String protoKey : protoKeys) {
        if (reset || !cache.containsKey(protoKey)) {
            String protoContent = IoUtil.toString(getClass().getResourceAsStream("/" + protoKey));
            log.info(String.format("Using proto schema: %s%n%s", protoKey, protoContent));
            fds.addProtoFile(protoKey, protoContent);
            cache.put(protoKey, protoContent);
        }
    }
    ctx.registerProtoFiles(fds);
    ctx.registerMarshaller(new ArtifactTypeMarshaller());
    ctx.registerMarshaller(new ArtifactMarshaller());
}
 
Example #2
Source File: ProtoStreamObjectMarshallingStrategy.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public ProtoStreamObjectMarshallingStrategy(String proto, MessageMarshaller<?>...marshallers) {
    serializationContext = new SerializationContextImpl(Configuration.builder().build());        
    
    try {
        serializationContext.registerProtoFiles(FileDescriptorSource.fromResources("kogito-types.proto"));
        registerMarshaller(new StringMessageMarshaller(),
                            new IntegerMessageMarshaller(),
                            new LongMessageMarshaller(),
                            new DoubleMessageMarshaller(),
                            new FloatMessageMarshaller(),
                            new BooleanMessageMarshaller(),
                            new DateMessageMarshaller());
        
        if (proto != null) {
            serializationContext.registerProtoFiles(FileDescriptorSource.fromString(UUID.randomUUID().toString(), proto));
                            
            registerMarshaller(marshallers);
            
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    
}
 
Example #3
Source File: MarshallerConfiguration.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Produces
FileDescriptorSource bookProtoDefinition() {
    return FileDescriptorSource.fromString("magazine.proto", "package magazine_sample;\n" +
            "\n" +
            "message Magazine {\n" +
            "  required string name = 1;\n" +
            "  required int32 publicationYear = 2;\n" +
            "  required int32 publicationMonth = 3;\n" +
            "  repeated string stories = 4;\n" +
            "}");
}
 
Example #4
Source File: Bucket4jProtobufContextInitializer.java    From bucket4j with Apache License 2.0 5 votes vote down vote up
@Override
public void registerSchema(SerializationContext serCtx) {
    StringBuilder protoBuilder = new StringBuilder(FOOTER);

    for (SerializationHandle<?> serializationHandle : Bucket4j.getSerializationHandles()) {
        String typeName = "Bucket4jType_" + serializationHandle.getTypeId();
        String typeDefinition = TYPE_TEMPLATE.replace("[type_name]", typeName);
        protoBuilder.append(typeDefinition);
    }

    String generatedProtoFile = protoBuilder.toString();
    FileDescriptorSource protoSource = FileDescriptorSource.fromString(getProtoFileName(), generatedProtoFile);
    serCtx.registerProtoFiles(protoSource);
}
 
Example #5
Source File: MarshallerGenerator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public List<CompilationUnit> generateFromClasspath(String protoFile) throws IOException {
    FileDescriptorSource proto = FileDescriptorSource.fromResources(protoFile);

    return generate(proto);
}
 
Example #6
Source File: MarshallerGenerator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public List<CompilationUnit> generate(String content) throws IOException {
    FileDescriptorSource proto = FileDescriptorSource.fromString(UUID.randomUUID().toString(), content);

    return generate(proto);
}
 
Example #7
Source File: InfinispanClientProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
UnremovableBeanBuildItem ensureBeanLookupAvailable() {
    return UnremovableBeanBuildItem.beanTypes(BaseMarshaller.class, EnumMarshaller.class, MessageMarshaller.class,
            RawProtobufMarshaller.class, FileDescriptorSource.class);
}