本文整理汇总了Java中com.google.protobuf.Descriptors.DescriptorValidationException类的典型用法代码示例。如果您正苦于以下问题:Java DescriptorValidationException类的具体用法?Java DescriptorValidationException怎么用?Java DescriptorValidationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DescriptorValidationException类属于com.google.protobuf.Descriptors包,在下文中一共展示了DescriptorValidationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromFileDescriptorSet
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
/** Creates a resolver which searches the supplied {@link FileDescriptorSet}. */
public static ServiceResolver fromFileDescriptorSet(FileDescriptorSet descriptorSet) {
ImmutableMap<String, FileDescriptorProto> descriptorProtoIndex =
computeDescriptorProtoIndex(descriptorSet);
Map<String, FileDescriptor> descriptorCache = new HashMap<>();
ImmutableList.Builder<FileDescriptor> result = ImmutableList.builder();
for (FileDescriptorProto descriptorProto : descriptorSet.getFileList()) {
try {
result.add(descriptorFromProto(descriptorProto, descriptorProtoIndex, descriptorCache));
} catch (DescriptorValidationException e) {
logger.warn("Skipped descriptor " + descriptorProto.getName() + " due to error", e);
continue;
}
}
return new ServiceResolver(result.build());
}
示例2: descriptorFromProto
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
/**
* Recursively constructs file descriptors for all dependencies of the supplied proto and returns
* a {@link FileDescriptor} for the supplied proto itself. For maximal efficiency, reuse the
* descriptorCache argument across calls.
*/
private static FileDescriptor descriptorFromProto(
FileDescriptorProto descriptorProto,
ImmutableMap<String, FileDescriptorProto> descriptorProtoIndex,
Map<String, FileDescriptor> descriptorCache) throws DescriptorValidationException {
// First, check the cache.
String descritorName = descriptorProto.getName();
if (descriptorCache.containsKey(descritorName)) {
return descriptorCache.get(descritorName);
}
// Then, fetch all the required dependencies recursively.
ImmutableList.Builder<FileDescriptor> dependencies = ImmutableList.builder();
for (String dependencyName : descriptorProto.getDependencyList()) {
if (!descriptorProtoIndex.containsKey(dependencyName)) {
throw new IllegalArgumentException("Could not find dependency: " + dependencyName);
}
FileDescriptorProto dependencyProto = descriptorProtoIndex.get(dependencyName);
dependencies.add(descriptorFromProto(dependencyProto, descriptorProtoIndex, descriptorCache));
}
// Finally, construct the actual descriptor.
FileDescriptor[] empty = new FileDescriptor[0];
return FileDescriptor.buildFrom(descriptorProto, dependencies.build().toArray(empty));
}
示例3: testInvalidPublicDependency
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
public void testInvalidPublicDependency() throws Exception {
FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
.setName("foo.proto").build();
FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
.setName("boo.proto")
.addDependency("foo.proto")
.addPublicDependency(1) // Error, should be 0.
.build();
FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
new FileDescriptor[0]);
try {
Descriptors.FileDescriptor.buildFrom(barProto,
new FileDescriptor[] {fooFile});
fail("DescriptorValidationException expected");
} catch (DescriptorValidationException e) {
assertTrue(
e.getMessage().indexOf("Invalid public dependency index.") != -1);
}
}
示例4: getDeepCanonicalFileDescriptor
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
private FileDescriptor getDeepCanonicalFileDescriptor(final FileDescriptor file,
final boolean forceRebuild) throws DescriptorValidationException {
if (!forceRebuild && isDeeplyCanonical(file)) {
return file;
}
final FileDescriptor[] dependencies = new FileDescriptor[file.getDependencies().size()];
int i = 0;
for (final FileDescriptor dependency : file.getDependencies()) {
dependencies[i++] = getDeepCanonicalFileDescriptor(dependency, forceRebuild);
}
final FileDescriptorProto proto = isCanonical(file) ? file.toProto() : makeCanonicalProto(file);
return buildFileDescriptorWithReserializedProto(proto, dependencies);
}
示例5: data
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
@Parameters(name = "{index}:{0}")
public static Collection<Object[]> data() {
return ImmutableList.<Object[]>of(new Object[] {"NonUniqueFieldName1.proto",
NonUniqueException.class, "field name"}, new Object[] {"NonUniqueFieldNumber1.proto",
NonUniqueException.class, "field number"}, new Object[] {"FieldsInExtensionRange1.proto",
FieldInExtensionRangeException.class, ""}, new Object[] {"InvalidExtensionRange1.proto",
InvalidExtensionRange.class, ""}, new Object[] {"InvalidExtensionRange2.proto",
InvalidExtensionRange.class, ""}, new Object[] {"InvalidExtensionRange3.proto",
InvalidExtensionRange.class, ""}, new Object[] {"UnresolvedTypeName1.proto",
UnresolvedTypeNameException.class, ""}, new Object[] {"UnresolvedTypeName2.proto",
UnresolvedTypeNameException.class, ""}, new Object[] {"UnresolvedTypeName3.proto",
UnresolvedTypeNameException.class, ""}
, new Object[] {"UnresolvedTypeName4.proto", DescriptorValidationException.class, ""},
new Object[] {"UnresolvedTypeName5.proto", DescriptorValidationException.class, ""}
, new Object[] {"NonUniqueExtensionName1.proto", DescriptorValidationException.class, ""},
new Object[] {"NonUniqueExtensionNumber1.proto", NonUniqueExtensionNumber.class, ""});
}
示例6: buildDescriptor
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
private static FileDescriptor buildDescriptor(
String name,
Map<String, FileDescriptor> descriptors,
Map<String, FileDescriptorProto> protos)
throws DescriptorValidationException {
FileDescriptor file = descriptors.get(name);
if (file != null) {
return file;
}
FileDescriptorProto proto = protos.get(name);
FileDescriptor[] deps = new FileDescriptor[proto.getDependencyCount()];
for (int i = 0; i < proto.getDependencyCount(); i++) {
deps[i] = buildDescriptor(proto.getDependency(i), descriptors, protos);
}
file = FileDescriptor.buildFrom(proto, deps);
descriptors.put(name, file);
return file;
}
示例7: build
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
/**
* Builds the new {@code SoyFileSet}.
*
* @return The new {@code SoyFileSet}.
*/
public SoyFileSet build() {
try {
if (!protoTypeProviderBuilder.isEmpty()) {
Set<SoyTypeProvider> typeProviders =
ImmutableSet.<SoyTypeProvider>of(protoTypeProviderBuilder.build());
localTypeRegistry = new SoyTypeRegistry(typeProviders);
}
} catch (DescriptorValidationException | IOException ex) {
throw new RuntimeException("Malformed descriptor set", ex);
}
return new SoyFileSet(
coreDependencies.apiCallScope,
coreDependencies.soyValueConverter,
localTypeRegistry == null ? coreDependencies.typeRegistry : localTypeRegistry,
coreDependencies.soyFunctionMap,
coreDependencies.printDirectives,
filesBuilder.build(),
getGeneralOptions(),
cache,
conformanceConfig,
loggingConfig,
warningSink);
}
示例8: testInvalidPublicDependency
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
public void testInvalidPublicDependency() throws Exception {
FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
.setName("foo.proto") .build();
FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
.setName("boo.proto")
.addDependency("foo.proto")
.addPublicDependency(1) // Error, should be 0.
.build();
FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
new FileDescriptor[0]);
try {
Descriptors.FileDescriptor.buildFrom(barProto,
new FileDescriptor[] {fooFile});
fail("DescriptorValidationException expected");
} catch (DescriptorValidationException e) {
assertTrue(
e.getMessage().indexOf("Invalid public dependency index.") != -1);
}
}
示例9: testUnknownFieldsDenied
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
public void testUnknownFieldsDenied() throws Exception {
FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
.setName("foo.proto")
.addMessageType(DescriptorProto.newBuilder()
.setName("Foo")
.addField(FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setTypeName("Bar")
.setName("bar")
.setNumber(1)))
.build();
try {
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
fail("DescriptorValidationException expected");
} catch (DescriptorValidationException e) {
assertTrue(e.getMessage().indexOf("Bar") != -1);
assertTrue(e.getMessage().indexOf("is not defined") != -1);
}
}
示例10: testDescriptorValidatorException
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
/**
* Tests that the DescriptorValidationException works as intended.
*/
public void testDescriptorValidatorException() throws Exception {
FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
.setName("foo.proto")
.addMessageType(DescriptorProto.newBuilder()
.setName("Foo")
.addField(FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(FieldDescriptorProto.Type.TYPE_INT32)
.setName("foo")
.setNumber(1)
.setDefaultValue("invalid")
.build())
.build())
.build();
try {
Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
new FileDescriptor[0]);
fail("DescriptorValidationException expected");
} catch (DescriptorValidationException e) {
// Expected; check that the error message contains some useful hints
assertTrue(e.getMessage().indexOf("foo") != -1);
assertTrue(e.getMessage().indexOf("Foo") != -1);
assertTrue(e.getMessage().indexOf("invalid") != -1);
assertTrue(e.getCause() instanceof NumberFormatException);
assertTrue(e.getCause().getMessage().indexOf("invalid") != -1);
}
}
示例11: CausalOrderProtobufSerializer
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
public CausalOrderProtobufSerializer(@NotNull final Serializer<T> objectSerializer) {
this.objectSerializer = objectSerializer;
try {
final FileDescriptorProto timestampedMessageFile = FileDescriptorProto.newBuilder()
.addMessageType(
DescriptorProto.newBuilder()
.setName(MESSAGE_NAME)
.addField(
FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
.setName(IDS_FIELD_NAME)
.setNumber(IDS_FIELD_NUMBER)
.setType(FieldDescriptorProto.Type.TYPE_BYTES))
.addField(
FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
.setName(TIMESTAMPS_FIELD_NAME)
.setNumber(TIMESTAMPS_FIELD_NUMBER)
.setOptions(FieldOptions.newBuilder()
.setPacked(true))
.setType(FieldDescriptorProto.Type.TYPE_UINT64))
.addField(
FieldDescriptorProto.newBuilder()
.setName(VALUE_FIELD_NAME)
.setNumber(VALUE_FIELD_NUMBER)
.setType(FieldDescriptorProto.Type.TYPE_BYTES)))
.build();
this.messageDescriptor = FileDescriptor
.buildFrom(timestampedMessageFile, new FileDescriptor[0])
.findMessageTypeByName(MESSAGE_NAME);
this.ids = messageDescriptor.findFieldByName(IDS_FIELD_NAME);
this.timestamps = messageDescriptor.findFieldByName(TIMESTAMPS_FIELD_NAME);
this.value = messageDescriptor.findFieldByName(VALUE_FIELD_NAME);
this.messageParser = DynamicMessage.newBuilder(messageDescriptor)
.buildPartial()
.getParserForType();
} catch (final DescriptorValidationException e) {
throw new RuntimeException(e);
}
}
示例12: SingleSourceFifoOrderProtobufSerializer
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
public SingleSourceFifoOrderProtobufSerializer(@NotNull final Serializer<T> objectSerializer) {
this.objectSerializer = objectSerializer;
try {
final FileDescriptorProto timestampedMessageFile = FileDescriptorProto.newBuilder()
.addMessageType(
DescriptorProto.newBuilder()
.setName(MESSAGE_NAME)
.addField(
FieldDescriptorProto.newBuilder()
.setName(TIMESTAMP_FIELD_NAME)
.setNumber(TIMESTAMP_FIELD_NUMBER)
.setType(FieldDescriptorProto.Type.TYPE_INT64))
.addField(
FieldDescriptorProto.newBuilder()
.setName(VALUE_FIELD_NAME)
.setNumber(VALUE_FIELD_NUMBER)
.setType(FieldDescriptorProto.Type.TYPE_BYTES)))
.build();
final Descriptor message = FileDescriptor
.buildFrom(timestampedMessageFile, new FileDescriptor[0])
.findMessageTypeByName(MESSAGE_NAME);
this.timestampedMessageField = message.findFieldByName(TIMESTAMP_FIELD_NAME);
this.valueMessageField = message.findFieldByName(VALUE_FIELD_NAME);
this.messageBuilder = DynamicMessage.newBuilder(message);
this.messageParser = messageBuilder.buildPartial().getParserForType();
} catch (final DescriptorValidationException e) {
throw new RuntimeException(e);
}
}
示例13: buildRowDataConverter
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
static ProtobufRowDataConverter buildRowDataConverter(HasStorage object,
FileDescriptorProto fileProto) {
Group group = (Group)object;
FileDescriptor fileDescriptor;
try {
fileDescriptor = FileDescriptor.buildFrom(fileProto, DEPENDENCIES);
}
catch (DescriptorValidationException ex) {
throw new ProtobufBuildException(ex);
}
return ProtobufRowDataConverter.forGroup(group, fileDescriptor);
}
示例14: buildRowConverter
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
static ProtobufRowConverter buildRowConverter(HasStorage object, FileDescriptorProto fileProto) {
Group group = (Group) object;
FileDescriptor fileDescriptor;
try {
fileDescriptor = FileDescriptor.buildFrom(fileProto, DEPENDENCIES);
}
catch (DescriptorValidationException ex) {
throw new ProtobufBuildException(ex);
}
return ProtobufRowConverter.forGroup(group, fileDescriptor);
}
示例15: parseFrom
import com.google.protobuf.Descriptors.DescriptorValidationException; //导入依赖的package包/类
/**
* Parses a serialized schema descriptor (from input stream; closes the stream)
*
* @param schemaDescIn the descriptor input stream
* @return the schema object
* @throws DescriptorValidationException
* @throws IOException
*/
public static DynamicSchema parseFrom(InputStream schemaDescIn) throws DescriptorValidationException, IOException {
try {
int len;
byte[] buf = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((len = schemaDescIn.read(buf)) > 0) baos.write(buf, 0, len);
return parseFrom(baos.toByteArray());
}
finally {
schemaDescIn.close();
}
}