Java Code Examples for com.google.protobuf.DescriptorProtos.FileDescriptorSet#newBuilder()

The following examples show how to use com.google.protobuf.DescriptorProtos.FileDescriptorSet#newBuilder() . 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: ProtobufReflectionUtil.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
static FileDescriptorSet protoFileDescriptorSet(Descriptor descriptor) {
  Set<FileDescriptor> descriptors = new HashSet<>();
  descriptors.add(descriptor.getFile());
  addDependenciesRecursively(descriptors, descriptor.getFile());

  Builder fileDescriptorSet = FileDescriptorSet.newBuilder();
  for (FileDescriptor d : descriptors) {
    fileDescriptorSet.addFile(d.toProto());
  }
  return fileDescriptorSet.build();
}
 
Example 2
Source File: ProtobufReflectionUtil.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
static FileDescriptorSet protoFileDescriptorSet(Descriptor descriptor) {
  Set<FileDescriptor> descriptors = new HashSet<>();
  descriptors.add(descriptor.getFile());
  addDependenciesRecursively(descriptors, descriptor.getFile());

  Builder fileDescriptorSet = FileDescriptorSet.newBuilder();
  for (FileDescriptor d : descriptors) {
    fileDescriptorSet.addFile(d.toProto());
  }
  return fileDescriptorSet.build();
}
 
Example 3
Source File: DescriptorGenerator.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private FileDescriptorSet generate() {
  FileDescriptorSet.Builder setBuilder = FileDescriptorSet.newBuilder();
  for (Map.Entry<String, FileContents> entry : contentsByFile.entrySet()) {
    FileContents contents = entry.getValue();
    String fileName = entry.getKey();
    if (!contents.apis.isEmpty() || !contents.types.isEmpty() || !contents.enums.isEmpty()) {
      setBuilder.addFile(generateFile(fileName, contents));
    }
  }
  return setBuilder.build();
}
 
Example 4
Source File: DynamicSchema.java    From protobuf-dynamic with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a dynamic schema
 * 
 * @return the schema object
 * @throws DescriptorValidationException
 */
public DynamicSchema build() throws DescriptorValidationException {
	FileDescriptorSet.Builder fileDescSetBuilder = FileDescriptorSet.newBuilder();
	fileDescSetBuilder.addFile(mFileDescProtoBuilder.build());
	fileDescSetBuilder.mergeFrom(mFileDescSetBuilder.build());
	return new DynamicSchema(fileDescSetBuilder.build());
}
 
Example 5
Source File: AISToProtobuf.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public AISToProtobuf(ProtobufRowFormat.Type formatType, FileDescriptorSet priorSet) {
    this.formatType = formatType;
    this.priorSet = priorSet;
    setBuilder = FileDescriptorSet.newBuilder();
}
 
Example 6
Source File: ProtobufStorageDescriptionHelper.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
static FileDescriptorProto validateAndGenerate(HasStorage object,
                                               ProtobufRowFormat.Type formatType,
                                               FileDescriptorProto fileProto,
                                               AISValidationOutput output) {
    if (!(object instanceof Group)) {
        output.reportFailure(new AISValidationFailure(new StorageDescriptionInvalidException(object, "is not a Group and cannot use Protocol Buffers")));
        return null;
    }
    Group group = (Group)object;
    if (formatType == ProtobufRowFormat.Type.SINGLE_TABLE) {
        if (!group.getRoot().getChildJoins().isEmpty()) {
            output.reportFailure(new AISValidationFailure(new StorageDescriptionInvalidException(object, "has more than one table")));
            return null;
        }
    }
    int currentVersion = sumTableVersions(group.getRoot());
    if (fileProto != null) {
        int storedVersion = fileProto.getOptions()
            .getExtension(CustomOptions.GroupOptions.fdbsql).getVersion();
        if (storedVersion == currentVersion) {
            return fileProto;
        }
    }
    FileDescriptorSet set = null;
    if (fileProto != null) {
        FileDescriptorSet.Builder builder = FileDescriptorSet.newBuilder();
        builder.addFile(fileProto);
        set = builder.build();
    }
    AISToProtobuf ais2p = new AISToProtobuf(formatType, set);
    ais2p.addGroup(group);
    set = ais2p.build();
    fileProto = set.getFile(0); // Only added one group.
    // Make sure it will build before committing to this format.
    try {
        FileDescriptor.buildFrom(fileProto, DEPENDENCIES);
    }
    catch (DescriptorValidationException ex) {
        output.reportFailure(new AISValidationFailure(new ProtobufBuildException(ex)));
    }
    return fileProto;
}
 
Example 7
Source File: DynamicSchema.java    From protobuf-dynamic with Apache License 2.0 4 votes vote down vote up
private Builder() {
	mFileDescProtoBuilder = FileDescriptorProto.newBuilder();
	mFileDescSetBuilder = FileDescriptorSet.newBuilder();
}