org.apache.avro.Protocol.getTypes()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.apache.avro.Protocol.getTypes()方法的一些代码示例,展示了Protocol.getTypes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.getTypes()方法的具体详情如下:
包路径:org.apache.avro.Protocol
类名称:Protocol
方法名:getTypes

Protocol.getTypes介绍

[英]The types of this protocol.
[中]该协议的类型。

代码示例

代码示例来源:origin: apache/avro

public SpecificCompiler(Protocol protocol, DateTimeLogicalTypeImplementation dateTimeLogicalTypeImplementation) {
 this(dateTimeLogicalTypeImplementation);
 // enqueue all types
 for (Schema s : protocol.getTypes()) {
  enqueue(s);
 }
 this.protocol = protocol;
}

代码示例来源:origin: apache/avro

@Override
public int run(InputStream in, PrintStream out, PrintStream err,
  List<String> args) throws Exception {
 if (args.isEmpty() || args.size() > 2 || isRequestingHelp(args)) {
  err.println("Usage: idl2schemata [idl] [outdir]");
  err.println("");
  err.println("If an output directory is not specified, "
    + "outputs to current directory.");
  return -1;
 }
 boolean pretty = true;
 Idl parser = new Idl(new File(args.get(0)));
 File outputDirectory = getOutputDirectory(args);
 for (Schema schema : parser.CompilationUnit().getTypes()) {
  print(schema, outputDirectory, pretty);
 }
 parser.close();
 return 0;
}

代码示例来源:origin: apache/avro

@Test
public void testForwardReference() {
 ReflectData data = ReflectData.get();
 Protocol reflected = data.getProtocol(C.class);
 Protocol reparsed = Protocol.parse(reflected.toString());
 assertEquals(reflected, reparsed);
 assert(reparsed.getTypes().contains(data.getSchema(A.class)));
 assert(reparsed.getTypes().contains(data.getSchema(B1.class)));
 assert(reparsed.getTypes().contains(data.getSchema(B2.class)));
 assert(reparsed.getTypes().contains(data.getSchema(X.class)));
}

代码示例来源:origin: apache/avro

private Protocol addStringType(Protocol p) {
 if (stringType != StringType.String)
  return p;
 Protocol newP = new Protocol(p.getName(), p.getDoc(), p.getNamespace());
 Map<Schema,Schema> types = new LinkedHashMap<>();
 for (Map.Entry<String, Object> a : p.getObjectProps().entrySet()) {
  newP.addProp(a.getKey(), a.getValue());
 }
 // annotate types
 Collection<Schema> namedTypes = new LinkedHashSet<>();
 for (Schema s : p.getTypes())
  namedTypes.add(addStringType(s, types));
 newP.setTypes(namedTypes);
 // annotate messages
 Map<String,Message> newM = newP.getMessages();
 for (Message m : p.getMessages().values())
  newM.put(m.getName(), m.isOneWay()
       ? newP.createMessage(m,
                 addStringType(m.getRequest(), types))
       : newP.createMessage(m,
                 addStringType(m.getRequest(), types),
                 addStringType(m.getResponse(), types),
                 addStringType(m.getErrors(), types)));
 return newP;
}

代码示例来源:origin: apache/avro

final Collection<Schema> types = protocol.getTypes();

代码示例来源:origin: apache/avro

throw new ParseException();
for (Schema s : importProtocol.getTypes())
 names.put(s.getFullName(), s);
p.getMessages().putAll(importProtocol.getMessages());

代码示例来源:origin: org.apache.hadoop/avro

public SpecificCompiler(Protocol protocol) {
 // enqueue all types
 for (Schema s : protocol.getTypes()) {
  enqueue(s);
 }
 this.protocol = protocol;
}

代码示例来源:origin: org.apache.cassandra.deps/avro

public SpecificCompiler(Protocol protocol) {
 // enqueue all types
 for (Schema s : protocol.getTypes()) {
  enqueue(s);
 }
 this.protocol = protocol;
}

代码示例来源:origin: zolyfarkas/spf4j

private void publishSchemasAndAttachMvnIdToProtocol(final Protocol protocol,
    final boolean addMvnId) throws IOException {
 Collection<Schema> types = protocol.getTypes();
 Set<String> typeNames = Sets.newHashSetWithExpectedSize(types.size());
 for (Schema schema : types) {
  String fullName = schema.getFullName();
  if (!typeNames.add(fullName)) {
   continue;
  }
  if (addMvnId) {
   attachMavenId(schema);
  }
  String targetName = fullName.replace('.', File.separatorChar) + ".avsc";
  Path destinationFile = generatedAvscTarget.toPath().resolve(targetName);
  Path parent = destinationFile.getParent();
  if (parent != null) {
   Files.createDirectories(parent);
  }
  Files.write(destinationFile, schema.toString().getBytes(StandardCharsets.UTF_8),
      StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
 }
}

代码示例来源:origin: zolyfarkas/spf4j

Idl parser = new Idl(idl, cl);
Protocol protocol = parser.CompilationUnit();
for (Schema s : protocol.getTypes()) {
 if (s.getProp("mvnId") != null) {
  continue;

代码示例来源:origin: org.apache.avro/avro-tools

@Override
public int run(InputStream in, PrintStream out, PrintStream err,
  List<String> args) throws Exception {
 if (args.isEmpty() || args.size() > 2 || isRequestingHelp(args)) {
  err.println("Usage: idl2schemata [idl] [outdir]");
  err.println("");
  err.println("If an output directory is not specified, "
    + "outputs to current directory.");
  return -1;
 }
 boolean pretty = true;
 Idl parser = new Idl(new File(args.get(0)));
 File outputDirectory = getOutputDirectory(args);
 for (Schema schema : parser.CompilationUnit().getTypes()) {
  print(schema, outputDirectory, pretty);
 }
 parser.close();
 return 0;
}

代码示例来源:origin: commercehub-oss/gradle-avro-plugin

private void processProtoFile(File sourceFile) {
    getLogger().info("Processing {}", sourceFile);
    try {
      Protocol protocol = Protocol.parse(sourceFile);
      for (Schema schema : protocol.getTypes()) {
        String path = schema.getNamespace().replaceAll(Pattern.quote("."), "/");
        File schemaFile = new File(getOutputDir(), path + "/" + schema.getName() + "." + SCHEMA_EXTENSION);
        String schemaJson = schema.toString(true);
        FileUtils.writeJsonFile(schemaFile, schemaJson);
        getLogger().debug("Wrote {}", schemaFile.getPath());
      }
    } catch (IOException ex) {
      throw new GradleException(String.format("Failed to process protocol definition file %s", sourceFile), ex);
    }
  }
}

相关文章