use of com.google.protobuf.ExtensionRegistry in project beam by apache.
the class ProtoCoder method getExtensionRegistry.
/**
* Returns the {@link ExtensionRegistry} listing all known Protocol Buffers extension messages
* to {@code T} registered with this {@link ProtoCoder}.
*/
public ExtensionRegistry getExtensionRegistry() {
if (memoizedExtensionRegistry == null) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
for (Class<?> extensionHost : extensionHostClasses) {
try {
extensionHost.getDeclaredMethod("registerAllExtensions", ExtensionRegistry.class).invoke(null, registry);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
memoizedExtensionRegistry = registry.getUnmodifiable();
}
return memoizedExtensionRegistry;
}
use of com.google.protobuf.ExtensionRegistry in project beam by apache.
the class ProtobufUtil method verifyDeterministic.
/**
* Recursively checks whether the specified class uses any Protocol Buffers fields that cannot
* be deterministically encoded.
*
* @throws NonDeterministicException if the object cannot be encoded deterministically.
*/
static void verifyDeterministic(ProtoCoder<?> coder) throws NonDeterministicException {
Class<? extends Message> message = coder.getMessageType();
ExtensionRegistry registry = coder.getExtensionRegistry();
Set<Descriptor> descriptors = getRecursiveDescriptorsForClass(message, registry);
for (Descriptor d : descriptors) {
for (FieldDescriptor fd : d.getFields()) {
// be encoded deterministically.
if (fd.isMapField()) {
String reason = String.format("Protocol Buffers message %s transitively includes Map field %s (from file %s)." + " Maps cannot be deterministically encoded.", message.getName(), fd.getFullName(), fd.getFile().getFullName());
throw new NonDeterministicException(coder, reason);
}
}
}
}
use of com.google.protobuf.ExtensionRegistry in project drools by kiegroup.
the class AbstractKieModule method getCompilationCache.
@Override
public CompilationCache getCompilationCache(String kbaseName) {
// Map< DIALECT, Map< RESOURCE, List<BYTECODE> > >
CompilationCache cache = compilationCache.get(kbaseName);
if (cache == null) {
byte[] fileContents = getBytes(KieBuilderImpl.getCompilationCachePath(releaseId, kbaseName));
if (fileContents != null) {
ExtensionRegistry registry = KieModuleCacheHelper.buildRegistry();
try {
Header _header = KieModuleCacheHelper.readFromStreamWithHeaderPreloaded(new ByteArrayInputStream(fileContents), registry);
if (!Drools.isCompatible(_header.getVersion().getVersionMajor(), _header.getVersion().getVersionMinor(), _header.getVersion().getVersionRevision())) {
// if cache has been built with an incompatible version avoid to use it
log.warn("The compilation cache has been built with an incompatible version. " + "You should recompile your project in order to use it with current release.");
return null;
}
KModuleCache _cache = KModuleCache.parseFrom(_header.getPayload());
cache = new CompilationCache();
for (CompilationData _data : _cache.getCompilationDataList()) {
for (CompDataEntry _entry : _data.getEntryList()) {
cache.addEntry(_data.getDialect(), _entry.getId(), _entry.getData().toByteArray());
}
}
compilationCache.put(kbaseName, cache);
} catch (Exception e) {
log.error("Unable to load compilation cache... ", e);
}
}
}
return cache;
}
use of com.google.protobuf.ExtensionRegistry in project drools by kiegroup.
the class ProtobufInputMarshaller method loadAndParseSession.
private static ProtobufMessages.KnowledgeSession loadAndParseSession(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
ExtensionRegistry registry = PersisterHelper.buildRegistry(context, processMarshaller);
ProtobufMessages.Header _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
return ProtobufMessages.KnowledgeSession.parseFrom(_header.getPayload(), registry);
}
Aggregations