/** * get IDL content from class. * * @param cls target protobuf class to parse * @return protobuf IDL content in string */ public static String getIDL(final Class<?> cls) { return getIDL(cls, null, null); }
code.append(getFieldRequired(field.isRequired())).append(" ").append(c.getSimpleName()).append(" ") .append(field.getField().getName()).append("=").append(field.getOrder()).append(";\n"); if (field.getFieldType() == FieldType.ENUM) { String required = getFieldRequired(field.isRequired()); generateEnumIDL(code, subType); generateIDL(code, subType, cachedTypes, cachedEnumTypes);
generateIDL(code, cls, types, enumTypes);
/** * get IDL content from class. * * @param cls target class to parse for IDL message. * @param cachedTypes if type already in set will not generate IDL. if a new type found will add to set * @param cachedEnumTypes if enum already in set will not generate IDL. if a new enum found will add to set * @return protobuf IDL content in string * @see Protobuf */ public static String getIDL(final Class<?> cls, final Set<Class<?>> cachedTypes, final Set<Class<?>> cachedEnumTypes) { return getIDL(cls, cachedTypes, cachedEnumTypes, false); }
private static void writeProtoFile(Set<Class<?>> sourceClazzs){ for(Class clazz:sourceClazzs){ String filePath = MessageFormat.format("{0}.proto", new Object[]{clazz.getSimpleName()}); try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) { String source = ProtobufIDLGenerator.getIDL(clazz); String result = ""; for (String s : source.split("\n")) { if (s.startsWith("package ") || s.startsWith("option ")) { continue; } result += s + "\n"; } writer.write(result); } catch (IOException e) { e.printStackTrace(); } } System.out.println("completed"); }
ProtobufIDLGenerator.getIDL(rpcHandler.getInputClass(), cachedTypes, cachedEnumTypes, true); if (idl != null) { typesIDL.append(meta.getInputMetaProto()).append(LINE_BREAK); .getIDL(rpcHandler.getOutputClass(), cachedTypes, cachedEnumTypes, true); if (idl != null) { typesIDL.append(meta.getOutputMetaProto()).append(LINE_BREAK);
String idl = ProtobufIDLGenerator.getIDL(cls); ProtoFile file = ProtoSchemaParser.parse(ProtobufIDLProxy.DEFAULT_FILE_NAME, idl);