/** * Registers a protobuf file * @param fileName The name of the file. * @param contents The contents of the file. * @param dynamicEntityClass The dynamic entity class. * the types in the protobuf. * @throws IOException in case the registration fails. */ void registerSchema(String fileName, String contents, Class<?> dynamicEntityClass) throws IOException { getSerializationContext().registerProtoFiles(FileDescriptorSource.fromString(fileName, contents)); getSerializationContext().getFileDescriptors().entrySet().stream() .filter(p -> p.getKey().equals(fileName)) .flatMap(fd -> fd.getValue().getMessageTypes().stream()) .map(AnnotatedDescriptorImpl::getFullName) .forEach(t -> classByType.put(t, dynamicEntityClass)); }
/** * Registers a protobuf file * @param fileName The name of the file. * @param contents The contents of the file. * @param dynamicEntityClass The dynamic entity class. * the types in the protobuf. * @throws IOException in case the registration fails. */ void registerSchema(String fileName, String contents, Class<?> dynamicEntityClass) throws IOException { getSerializationContext().registerProtoFiles(FileDescriptorSource.fromString(fileName, contents)); getSerializationContext().getFileDescriptors().entrySet().stream() .filter(p -> p.getKey().equals(fileName)) .flatMap(fd -> fd.getValue().getMessageTypes().stream()) .map(AnnotatedDescriptorImpl::getFullName) .forEach(t -> classByType.put(t, dynamicEntityClass)); }
private FileDescriptor parseSchema() throws DescriptorParserException, IOException { FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString( schemaName, protoSchema ); Configuration config = Configuration.builder().build(); SerializationContext serCtx = ProtobufUtil.newSerializationContext( config ); serCtx.registerProtoFiles( fileDescriptorSource ); return serCtx.getFileDescriptors().get( schemaName ); } }