use of com.google.protobuf.UnknownFieldSet in project compiler by boalang.
the class JsonFormat method printUnknownFields.
protected static void printUnknownFields(UnknownFieldSet unknownFields, JsonGenerator generator) throws IOException {
boolean firstField = true;
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
UnknownFieldSet.Field field = entry.getValue();
if (firstField) {
firstField = false;
} else {
generator.print(", ");
}
generator.print("\"");
generator.print(entry.getKey().toString());
generator.print("\"");
generator.print(": [");
boolean firstValue = true;
for (long value : field.getVarintList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(unsignedToString(value));
}
for (int value : field.getFixed32List()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(String.format((Locale) null, "0x%08x", value));
}
for (long value : field.getFixed64List()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(String.format((Locale) null, "0x%016x", value));
}
for (ByteString value : field.getLengthDelimitedList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print("\"");
generator.print(escapeBytes(value));
generator.print("\"");
}
for (UnknownFieldSet value : field.getGroupList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print("{\n");
printUnknownFields(value, generator);
generator.print("}\n");
}
generator.print("]");
}
}
use of com.google.protobuf.UnknownFieldSet in project jvm-serializers by eishay.
the class JsonFormat method printUnknownFields.
private static void printUnknownFields(UnknownFieldSet unknownFields, JsonGenerator generator) throws IOException {
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
// String prefix = entry.getKey().toString() + ": ";
UnknownFieldSet.Field field = entry.getValue();
for (long value : field.getVarintList()) {
generator.print("\"");
generator.print(entry.getKey().toString());
generator.print("\"");
generator.print(": ");
generator.print(unsignedToString(value));
generator.print("\n");
}
for (int value : field.getFixed32List()) {
generator.print("\"");
generator.print(entry.getKey().toString());
generator.print("\"");
generator.print(": ");
generator.print(String.format((Locale) null, "0x%08x", value));
generator.print("\n");
}
for (long value : field.getFixed64List()) {
generator.print(entry.getKey().toString());
generator.print(": ");
generator.print(String.format((Locale) null, "0x%016x", value));
generator.print("\n");
}
for (ByteString value : field.getLengthDelimitedList()) {
generator.print(entry.getKey().toString());
generator.print(": \"");
generator.print(escapeBytes(value));
generator.print("\"\n");
}
for (UnknownFieldSet value : field.getGroupList()) {
generator.print(entry.getKey().toString());
generator.print(" {\n");
generator.indent();
printUnknownFields(value, generator);
generator.outdent();
generator.print("}\n");
}
}
}
use of com.google.protobuf.UnknownFieldSet in project gerrit by GerritCodeReview.
the class ProtobufImport method run.
@Override
public int run() throws Exception {
mustHaveValidSite();
Injector dbInjector = createDbInjector(SINGLE_USER);
manager.add(dbInjector);
manager.start();
RuntimeShutdown.add(manager::stop);
dbInjector.injectMembers(this);
ProgressMonitor progress = new TextProgressMonitor();
progress.beginTask("Importing entities", ProgressMonitor.UNKNOWN);
try (ReviewDb db = schemaFactory.open()) {
for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) {
relations.put(model.getRelationID(), Relation.create(model, db));
}
Parser<UnknownFieldSet> parser = UnknownFieldSet.getDefaultInstance().getParserForType();
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
UnknownFieldSet msg;
while ((msg = parser.parseDelimitedFrom(in)) != null) {
Map.Entry<Integer, UnknownFieldSet.Field> e = Iterables.getOnlyElement(msg.asMap().entrySet());
Relation rel = checkNotNull(relations.get(e.getKey()), "unknown relation ID %s in message: %s", e.getKey(), msg);
List<ByteString> values = e.getValue().getLengthDelimitedList();
checkState(values.size() == 1, "expected one string field in message: %s", msg);
upsert(rel, values.get(0));
progress.update(1);
}
}
progress.endTask();
}
return 0;
}
Aggregations