/** The syntax of the .proto file. */ public enum Syntax { UNKNOWN("unknown"), PROTO2("proto2"), PROTO3("proto3"); Syntax(String name) { this.name = name; } private final String name; }
result = buildFrom(proto, dependencies); } catch (DescriptorValidationException e) { throw new IllegalArgumentException(
try { this.builder.setSyntax("proto3"); final Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom( this.builder.build(), new Descriptors.FileDescriptor[]{});
private static FileDescriptor buildDescriptor( String requestor, 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); if (proto == null) { throw new IllegalStateException( "Cannot find proto descriptor for " + name + " which is a dependency of " + requestor); } FileDescriptor[] deps = new FileDescriptor[proto.getDependencyCount()]; for (int i = 0; i < proto.getDependencyCount(); i++) { deps[i] = buildDescriptor(name, proto.getDependency(i), descriptors, protos); } file = FileDescriptor.buildFrom(proto, deps); descriptors.put(name, file); return file; }
/** * Construct a {@code FileDescriptor}. * * @param proto The protocol message form of the FileDescriptor. * @param dependencies {@code FileDescriptor}s corresponding to all of * the file's dependencies. * @throws DescriptorValidationException {@code proto} is not a valid * descriptor. This can occur for a number of reasons, e.g. * because a field has an undefined type or because two messages * were defined with the same name. */ public static FileDescriptor buildFrom(final FileDescriptorProto proto, final FileDescriptor[] dependencies) throws DescriptorValidationException { return buildFrom(proto, dependencies, false); }
/** * Construct a {@code FileDescriptor}. * * @param proto The protocol message form of the FileDescriptor. * @param dependencies {@code FileDescriptor}s corresponding to all of * the file's dependencies. * @throws DescriptorValidationException {@code proto} is not a valid * descriptor. This can occur for a number of reasons, e.g. * because a field has an undefined type or because two messages * were defined with the same name. */ public static FileDescriptor buildFrom(final FileDescriptorProto proto, final FileDescriptor[] dependencies) throws DescriptorValidationException { return buildFrom(proto, dependencies, false); }
/** * Returns a Message {@link Descriptor} for a dynamically generated * DescriptorProto. * * @param descProto * @throws DescriptorValidationException */ public static Descriptor makeMessageDescriptor(DescriptorProto descProto) throws DescriptorValidationException { DescriptorProtos.FileDescriptorProto fileDescP = DescriptorProtos.FileDescriptorProto.newBuilder().addMessageType(descProto).build(); Descriptors.FileDescriptor[] fileDescs = new Descriptors.FileDescriptor[0]; Descriptors.FileDescriptor dynamicDescriptor = Descriptors.FileDescriptor.buildFrom(fileDescP, fileDescs); return dynamicDescriptor.findMessageTypeByName(descProto.getName()); }
private Descriptor getDescriptor(String descriptorFileInClassPath) { try { InputStream fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFileInClassPath); FileDescriptorSet set = FileDescriptorSet.parseFrom(fin); FileDescriptor file = FileDescriptor.buildFrom(set.getFile(0), new FileDescriptor[] {}); return file.getMessageTypes().get(0); } catch (Exception e) { throw Throwables.propagate(e); } }
private FileDescriptor createFileDescriptor(FileDescriptorProto fileProto, FileDescriptor[] dependencies) throws DescriptorValidationException { return FileDescriptor.buildFrom(fileProto, dependencies); }
public Descriptors.FileDescriptor getFileDescriptor() throws GrpcServerException { try { return Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new Descriptors.FileDescriptor[] {}); } catch (Descriptors.DescriptorValidationException e) { throw new GrpcServerException(e); } }
private static FileDescriptor hydrateFileDescriptorTree(FileDescriptorTreeProto proto) throws DescriptorValidationException, InvalidProtocolBufferException { FileDescriptor[] dependencies = new FileDescriptor[proto.getDependenciesCount()]; for (int i = 0; i < proto.getDependenciesCount(); i++) { dependencies[i] = hydrateFileDescriptorTree(proto.getDependencies(i)); } FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(proto.getProtoFileDescriptor()); return FileDescriptor.buildFrom(fileProto, dependencies); }
public ProtobufDecoderUsingDescriptor(byte[] bytes, String name) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException { this.gson = new Gson(); DescriptorProtos.FileDescriptorSet fileDescriptorSet = DescriptorProtos.FileDescriptorSet.parseFrom(bytes); DescriptorProtos.FileDescriptorProto fileProto = fileDescriptorSet.getFile(0); Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(fileProto, new Descriptors.FileDescriptor[0]); descriptor = fileDescriptor.findMessageTypeByName(name); }
/** The syntax of the .proto file. */ public enum Syntax { UNKNOWN("unknown"), PROTO2("proto2"), PROTO3("proto3"); Syntax(String name) { this.name = name; } private final String name; }
private Descriptors.FileDescriptor buildRecordDescriptor(@Nonnull DescriptorProtos.FileDescriptorProto proto) throws Descriptors.DescriptorValidationException { final Descriptors.FileDescriptor[] dependencies = new Descriptors.FileDescriptor[metaData.getRecordsDescriptor().getDependencies().size()]; metaData.getRecordsDescriptor().getDependencies().toArray(dependencies); return Descriptors.FileDescriptor.buildFrom(proto, dependencies); }
private static Descriptors.FileDescriptor buildFileDescriptor(@Nonnull DescriptorProtos.FileDescriptorProto fileDescriptorProto, @Nonnull Descriptors.FileDescriptor[] dependencies) { try { return Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, dependencies); } catch (Descriptors.DescriptorValidationException ex) { throw new MetaDataException("Error converting from protobuf", ex); } }
.build(); return Descriptors.FileDescriptor.buildFrom(DescriptorProtos.FileDescriptorProto.newBuilder() .addMessageType(elementDescriptor) .addMessageType(pathDescriptor)
} else if (message.hasProtoFileDescriptor()) { FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(message.getProtoFileDescriptor()); FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileProto, new FileDescriptor[0]); protoDescriptor = fileDescriptor.findMessageTypeByName(message.getProtoMessageName()); try { FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(message.getProtoFileDescriptor()); FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileProto, new FileDescriptor[0]); protoDescriptor = fileDescriptor.findMessageTypeByName(message.getProtoMessageName()); } catch (Exception e) {
FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileDescriptorProto, ar); loaded.put(fileDescriptor.getName(), fileDescriptor); for (Descriptor descriptor : fileDescriptor.getMessageTypes()) {
private static FileDescriptor hydrateFileDescriptorTree(FileDescriptorTreeProto proto) throws DescriptorValidationException, InvalidProtocolBufferException { FileDescriptor[] dependencies = new FileDescriptor[proto.getDependenciesCount()]; for (int i = 0; i < proto.getDependenciesCount(); i++) { dependencies[i] = hydrateFileDescriptorTree(proto.getDependencies(i)); } FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(proto.getProtoFileDescriptor()); return FileDescriptor.buildFrom(fileProto, dependencies); }
/** * Construct a {@code FileDescriptor}. * * @param proto The protocol message form of the FileDescriptor. * @param dependencies {@code FileDescriptor}s corresponding to all of * the file's dependencies. * @throws DescriptorValidationException {@code proto} is not a valid * descriptor. This can occur for a number of reasons, e.g. * because a field has an undefined type or because two messages * were defined with the same name. */ public static FileDescriptor buildFrom(final FileDescriptorProto proto, final FileDescriptor[] dependencies) throws DescriptorValidationException { return buildFrom(proto, dependencies, false); }