private void handleMissingField(String fieldName, JsonParser parser,
ExtensionRegistry extensionRegistry,
UnknownFieldSet.Builder builder) throws IOException {
JsonToken token = parser.nextToken();
if (token.equals(JsonToken.START_OBJECT)) {
// Message structure
token = parser.nextToken(); // skip name
while (token != null && !token.equals(JsonToken.END_OBJECT)) {
handleMissingField(fieldName, parser, extensionRegistry, builder);
token = parser.nextToken(); // get } or field name
}
} else if (token.equals(JsonToken.START_ARRAY)) {
// Collection
do {
handleMissingField(fieldName, parser, extensionRegistry, builder);
token = parser.getCurrentToken(); // got value or ]
} while (token != null && !token.equals(JsonToken.END_ARRAY));
} else {
// Primitive value
// NULL, INT, BOOL, STRING
// nothing to do..
}
}
java类com.google.protobuf.UnknownFieldSet的实例源码
JsonJacksonFormat.java 文件源码
项目:jigsaw-payment
阅读 32
收藏 0
点赞 0
评论 0
Validator.java 文件源码
项目:saluki
阅读 40
收藏 0
点赞 0
评论 0
/**
*
* @author liushiming
* @param args
* @since JDK 1.8
*/
public static void main(String[] args) {
CommandProtoc commondProtoc = CommandProtoc.configProtoPath(
"/Users/liushiming/project/java/saluki/saluki-plugin/saluki-plugin-common/src/test/java/com/quancheng/saluki",
new File(
"/Users/liushiming/project/java/saluki/saluki-example/saluki-example-api/target/protoc-dependencies"));
FileDescriptorSet fileDescriptorSet = commondProtoc.invoke(
"/Users/liushiming/project/java/saluki/saluki-plugin/saluki-plugin-common/src/test/java/com/quancheng/saluki/saluki_service.proto");
Map<Integer, UnknownFieldSet.Field> lengthDelimitedList = fileDescriptorSet.getFile(0)
.getMessageType(0).getField(0).getOptions().getUnknownFields().asMap();
for (Map.Entry<Integer, UnknownFieldSet.Field> integerFieldEntry : lengthDelimitedList
.entrySet()) {
for (ByteString byteString : integerFieldEntry.getValue().getLengthDelimitedList()) {
System.out.println(integerFieldEntry.getKey() + "--" + byteString.toStringUtf8());
}
}
System.out.println(fileDescriptorSet);
}
PB.java 文件源码
项目:nfs-rpc
阅读 25
收藏 0
点赞 0
评论 0
public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder(this.getUnknownFields());
while (true) {
int tag = input.readTag();
switch (tag) {
case 0:
this.setUnknownFields(unknownFields.build());
onChanged();
return this;
default: {
if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
this.setUnknownFields(unknownFields.build());
onChanged();
return this;
}
break;
}
case 10: {
bitField0_ |= 0x00000001;
bytesObject_ = input.readBytes();
break;
}
}
}
}
PB.java 文件源码
项目:nfs-rpc
阅读 28
收藏 0
点赞 0
评论 0
public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder(this.getUnknownFields());
while (true) {
int tag = input.readTag();
switch (tag) {
case 0:
this.setUnknownFields(unknownFields.build());
onChanged();
return this;
default: {
if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
this.setUnknownFields(unknownFields.build());
onChanged();
return this;
}
break;
}
case 10: {
bitField0_ |= 0x00000001;
bytesObject_ = input.readBytes();
break;
}
}
}
}
ProtobufTypeUtil.java 文件源码
项目:datacollector
阅读 42
收藏 0
点赞 0
评论 0
private static void handleUnknownFields(
Record record,
String fieldPath,
DynamicMessage.Builder builder
) throws IOException {
String path = fieldPath.isEmpty() ? FORWARD_SLASH : fieldPath;
String attribute = record.getHeader().getAttribute(ProtobufTypeUtil.PROTOBUF_UNKNOWN_FIELDS_PREFIX + path);
if (attribute != null) {
UnknownFieldSet.Builder unknownFieldBuilder = UnknownFieldSet.newBuilder();
unknownFieldBuilder.mergeDelimitedFrom(
new ByteArrayInputStream(
org.apache.commons.codec.binary.Base64.decodeBase64(attribute.getBytes(StandardCharsets.UTF_8))
)
);
UnknownFieldSet unknownFieldSet = unknownFieldBuilder.build();
builder.setUnknownFields(unknownFieldSet);
}
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 30
收藏 0
点赞 0
评论 0
public static void checkRecordForUnknownFields(Record record, int i) throws IOException {
// unknown fields are expected in paths for person and employee
String attribute = record.getHeader().getAttribute(ProtobufTypeUtil.PROTOBUF_UNKNOWN_FIELDS_PREFIX + "/");
UnknownFieldSet.Builder builder = UnknownFieldSet.newBuilder();
builder.mergeDelimitedFrom(new ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64(attribute.getBytes())));
UnknownFieldSet unknownFieldSet = builder.build();
UnknownFieldsUtil.checkEmployeeUnknownFields(unknownFieldSet);
if(i%2 == 0) {
attribute = record.getHeader().getAttribute(ProtobufTypeUtil.PROTOBUF_UNKNOWN_FIELDS_PREFIX + "/engineer/person");
} else {
attribute = record.getHeader().getAttribute(ProtobufTypeUtil.PROTOBUF_UNKNOWN_FIELDS_PREFIX + "/exec/person");
}
builder = UnknownFieldSet.newBuilder();
builder.mergeDelimitedFrom(new ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64(attribute.getBytes())));
unknownFieldSet = builder.build();
UnknownFieldsUtil.checkPersonUnknownFields(unknownFieldSet);
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 34
收藏 0
点赞 0
评论 0
public static UnknownFieldSet getEmployeeUnknownFields() {
// add unknown fields
UnknownFieldSet.Field unknownStringField = UnknownFieldSet.Field.newBuilder()
.addLengthDelimited(ByteString.copyFromUtf8("Hello San FRancisco!"))
.build();
UnknownFieldSet.Field unknownVarIntField = UnknownFieldSet.Field.newBuilder()
.addVarint(123456789)
.build();
UnknownFieldSet employeeUnknownFields = UnknownFieldSet.newBuilder()
.addField(345, unknownStringField)
.addField(456, unknownVarIntField)
.build();
return employeeUnknownFields;
}
DynamicMessageTest.java 文件源码
项目:protobuf-el
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void testToBuilder() throws Exception {
final IBuilder2 builder = messageProvider.newBuilder(TestAllTypes.getDescriptor());
reflectionTester.setAllFieldsViaReflection(builder);
final int unknownFieldNum = 9;
final long unknownFieldVal = 90;
builder.setUnknownFields(UnknownFieldSet
.newBuilder()
.addField(unknownFieldNum,
UnknownFieldSet.Field.newBuilder().addVarint(unknownFieldVal).build()).build());
final Message message = builder.build();
final Message derived = message.toBuilder().build();
reflectionTester.assertAllFieldsSetViaReflection(derived);
assertEquals(Arrays.asList(unknownFieldVal),
derived.getUnknownFields().getField(unknownFieldNum).getVarintList());
}
DescriptorFactory.java 文件源码
项目:protobuf-el
阅读 34
收藏 0
点赞 0
评论 0
private FieldDescriptorProto createFieldDescriptorProto(String name, int index, Type type,
String typeName, Label label, String defaultValue, String extendee,
UnknownFieldSet unknownFields, FieldOptions options) {
FieldDescriptorProto.Builder fieldBuilder = FieldDescriptorProto.newBuilder();
return fieldBuilder
.setName(name)
.setNumber(index)
.setType(type)
.setTypeName(typeName)
.setLabel(label)
.setDefaultValue(defaultValue)
.setExtendee(extendee)
.setUnknownFields(unknownFields)
.setOptions(options)
.build();
}
AbstractCharBasedFormatter.java 文件源码
项目:jigsaw-payment
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void print(UnknownFieldSet fields, OutputStream output, Charset cs)
throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(output, cs);
print(fields, writer);
writer.flush();
}
XmlJavaxFormat.java 文件源码
项目:jigsaw-payment
阅读 32
收藏 0
点赞 0
评论 0
/**
* Outputs a Smile representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, OutputStream output, Charset cs) throws IOException {
try {
XMLStreamWriter generator = createGenerator(output);
generator.writeStartElement(MESSAGE_ELEMENT);
printUnknownFields(fields, generator);
generator.writeEndElement();
generator.close();
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
XmlJavaxFormat.java 文件源码
项目:jigsaw-payment
阅读 34
收藏 0
点赞 0
评论 0
private void handleMissingField(String fieldName, XMLEventReader parser,
XMLEvent event, ExtensionRegistry extensionRegistry,
UnknownFieldSet.Builder builder) throws XMLStreamException {
// skip over the unknown fields, since we can't map them by id, then this message must not know about them.
// We 'could' map them into the UnknownFieldSet, however none of the other formatters support this..
// but in the future it would probably be useful for the case: Message A (v2) -> Message B (v1) -> Xml -> Message A (v2)
// this would require extra meta data in the xml to know the type of the unknown-field.
if (event.isStartElement()) {
/**
* This loop will eat up everything inside "6"
* So when this method is called, fieldName = 6, and event is set at index="11"
* <unknown-field index="6">
* <unknown-field index="11">566667</unknown-field>
* <unknown-field index="15">
* <unknown-field index="16">566667</unknown-field>
* </unknown-field>
* </unknown-field>
*/
int depth = 1; // we start 1 level down, the value of "6"
while (parser.hasNext()) {
XMLEvent nextEvent = parser.nextEvent();
if (nextEvent.isEndElement()) {
depth--;
if (depth <= 0 && parser.peek().isEndElement()) {
break;
}
} else if (nextEvent.isStartElement()) {
depth++;
}
}
} else if (event.isCharacters()) {
// done, let it slide.
}
}
CouchDBFormat.java 文件源码
项目:jigsaw-payment
阅读 33
收藏 0
点赞 0
评论 0
/**
* Outputs a textual representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, Appendable output) throws IOException {
CouchDBGenerator generator = new CouchDBGenerator(output);
generator.print("{");
printUnknownFields(fields, generator);
generator.print("}");
}
ProtobufFormatter.java 文件源码
项目:jigsaw-payment
阅读 31
收藏 0
点赞 0
评论 0
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public String printToString(final UnknownFieldSet fields) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
print(fields, out, defaultCharset);
out.flush();
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Writing to a StringBuilder threw an IOException (should never happen).",
e);
}
}
XmlFormat.java 文件源码
项目:jigsaw-payment
阅读 36
收藏 0
点赞 0
评论 0
/**
* Outputs a textual representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, Appendable output) throws IOException {
XmlGenerator generator = new XmlGenerator(output);
generator.print("<message>");
printUnknownFields(fields, generator);
generator.print("</message>");
}
JsonJacksonFormat.java 文件源码
项目:jigsaw-payment
阅读 32
收藏 0
点赞 0
评论 0
/**
* Outputs a Smile representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, OutputStream output, Charset cs) throws IOException {
JsonGenerator generator = createGenerator(output);
generator.writeStartObject();
printUnknownFields(fields, generator);
generator.writeEndObject();
generator.close();
}
HtmlFormat.java 文件源码
项目:jigsaw-payment
阅读 34
收藏 0
点赞 0
评论 0
public void print(final UnknownFieldSet fields, Appendable output) throws IOException {
HtmlGenerator generator = new HtmlGenerator(output);
generator.print("<html>");
generator.print(META_CONTENT);
generator.print("</head><body>");
printUnknownFields(fields, generator);
generator.print("</body></html>");
}
JsonFormat.java 文件源码
项目:jigsaw-payment
阅读 39
收藏 0
点赞 0
评论 0
/**
* Outputs a textual representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, Appendable output) throws IOException {
JsonGenerator generator = new JsonGenerator(output);
generator.print("{");
printUnknownFields(fields, generator);
generator.print("}");
}
PushSMPMessageProtos.java 文件源码
项目:TextSecureSMP
阅读 38
收藏 0
点赞 0
评论 0
private SyncMessageContext(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
boolean mutable_bitField0_ = false;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 10:
this.bitField0_ |= 1;
this.destination_ = input.readBytes();
break;
case 16:
this.bitField0_ |= 2;
this.timestamp_ = input.readUInt64();
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var11) {
throw var11.setUnfinishedMessage(this);
} catch (IOException var12) {
throw (new InvalidProtocolBufferException(var12.getMessage())).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
ProtobufImport.java 文件源码
项目:gerrit
阅读 24
收藏 0
点赞 0
评论 0
@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;
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 49
收藏 0
点赞 0
评论 0
public static void checkPersonUnknownFields(UnknownFieldSet unknownFieldSet) {
Map<Integer, UnknownFieldSet.Field> integerFieldMap = unknownFieldSet.asMap();
Assert.assertEquals(2, integerFieldMap.size());
Assert.assertTrue(integerFieldMap.containsKey(123));
Assert.assertEquals(1, integerFieldMap.get(123).getFixed32List().size());
Assert.assertEquals(1234, (int)integerFieldMap.get(123).getFixed32List().get(0));
Assert.assertTrue(integerFieldMap.containsKey(234));
Assert.assertEquals(1, integerFieldMap.get(234).getFixed64List().size());
Assert.assertEquals(12345678, (long)integerFieldMap.get(234).getFixed64List().get(0));
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 34
收藏 0
点赞 0
评论 0
public static void checkEmployeeUnknownFields(UnknownFieldSet unknownFieldSet) {
Map<Integer, UnknownFieldSet.Field> integerFieldMap = unknownFieldSet.asMap();
Assert.assertEquals(2, integerFieldMap.size());
Assert.assertTrue(integerFieldMap.containsKey(345));
Assert.assertEquals(1, integerFieldMap.get(345).getLengthDelimitedList().size());
Assert.assertEquals(
integerFieldMap.get(345).getLengthDelimitedList().get(0),
ByteString.copyFromUtf8("Hello San FRancisco!")
);
Assert.assertTrue(integerFieldMap.containsKey(456));
Assert.assertEquals(1, integerFieldMap.get(456).getVarintList().size());
Assert.assertEquals(123456789, (long)integerFieldMap.get(456).getVarintList().get(0));
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 32
收藏 0
点赞 0
评论 0
public static UnknownFieldSet getPersonUnknownFields() throws IOException {
// add unknown fields
UnknownFieldSet.Field unknownIntField = UnknownFieldSet.Field.newBuilder()
.addFixed32(1234)
.build();
UnknownFieldSet.Field unknownLongField = UnknownFieldSet.Field.newBuilder()
.addFixed64(12345678)
.build();
UnknownFieldSet unknownFieldSet = UnknownFieldSet.newBuilder()
.addField(123, unknownIntField)
.addField(234, unknownLongField)
.build();
return unknownFieldSet;
}
ProtobufTestUtil.java 文件源码
项目:datacollector
阅读 27
收藏 0
点赞 0
评论 0
public static byte[] getBytes(UnknownFieldSet unknownFieldSet) throws IOException {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
unknownFieldSet.writeDelimitedTo(bOut);
bOut.flush();
bOut.close();
return org.apache.commons.codec.binary.Base64.encodeBase64(bOut.toByteArray());
}
JsonFormat.java 文件源码
项目:compiler
阅读 29
收藏 0
点赞 0
评论 0
/**
* Outputs a textual representation of {@code fields} to {@code output}.
*/
public static void print(UnknownFieldSet fields, Appendable output) throws IOException {
JsonGenerator generator = new JsonGenerator(output);
generator.print("{\n");
generator.indent();
printUnknownFields(fields, generator);
generator.outdent();
generator.print("}");
}
JsonFormat.java 文件源码
项目:compiler
阅读 33
收藏 0
点赞 0
评论 0
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public static String printToString(UnknownFieldSet fields) {
try {
StringBuilder text = new StringBuilder();
print(fields, text);
return text.toString();
} catch (IOException e) {
throw new RuntimeException("Writing to a StringBuilder threw an IOException (should never happen).",
e);
}
}
AbstractCharBasedFormatter.java 文件源码
项目:tajo
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void print(UnknownFieldSet fields, OutputStream output, Charset cs)
throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(output, cs);
print(fields, writer);
writer.flush();
}
ProtobufFormatter.java 文件源码
项目:tajo
阅读 29
收藏 0
点赞 0
评论 0
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public String printToString(final UnknownFieldSet fields) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
print(fields, out, defaultCharset);
out.flush();
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Writing to a StringBuilder threw an IOException (should never happen).",
e);
}
}
AbstractCharBasedFormatter.java 文件源码
项目:incubator-tajo
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void print(UnknownFieldSet fields, OutputStream output, Charset cs)
throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(output, cs);
print(fields, writer);
writer.flush();
}
ProtobufFormatter.java 文件源码
项目:incubator-tajo
阅读 25
收藏 0
点赞 0
评论 0
/**
* Like {@code print()}, but writes directly to a {@code String} and returns it.
*/
public String printToString(final UnknownFieldSet fields) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
print(fields, out, defaultCharset);
out.flush();
return out.toString();
} catch (IOException e) {
throw new RuntimeException("Writing to a StringBuilder threw an IOException (should never happen).",
e);
}
}