当前位置: 首页>>代码示例>>Java>>正文


Java UnknownFieldSet类代码示例

本文整理汇总了Java中com.google.protobuf.UnknownFieldSet的典型用法代码示例。如果您正苦于以下问题:Java UnknownFieldSet类的具体用法?Java UnknownFieldSet怎么用?Java UnknownFieldSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnknownFieldSet类属于com.google.protobuf包,在下文中一共展示了UnknownFieldSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleMissingField

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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..
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:25,代码来源:JsonJacksonFormat.java

示例2: main

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
 * 
 * @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);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:25,代码来源:Validator.java

示例3: mergeFrom

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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;
    }
    }
  }
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:27,代码来源:PB.java

示例4: handleUnknownFields

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:ProtobufTypeUtil.java

示例5: checkRecordForUnknownFields

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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);
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:21,代码来源:ProtobufTestUtil.java

示例6: getEmployeeUnknownFields

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:17,代码来源:ProtobufTestUtil.java

示例7: testToBuilder

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
@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());
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:18,代码来源:DynamicMessageTest.java

示例8: createFieldDescriptorProto

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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(); 
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:17,代码来源:DescriptorFactory.java

示例9: print

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
@Override
public void print(UnknownFieldSet fields, OutputStream output, Charset cs)
		throws IOException {
	OutputStreamWriter writer = new OutputStreamWriter(output, cs);
	print(fields, writer);
	writer.flush();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:8,代码来源:AbstractCharBasedFormatter.java

示例10: print

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:16,代码来源:XmlJavaxFormat.java

示例11: handleMissingField

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
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.
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:38,代码来源:XmlJavaxFormat.java

示例12: print

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
 * 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("}");
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:10,代码来源:CouchDBFormat.java

示例13: printToString

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
    * 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);
       }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:15,代码来源:ProtobufFormatter.java

示例14: print

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
 * 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>");
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:10,代码来源:XmlFormat.java

示例15: print

import com.google.protobuf.UnknownFieldSet; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:11,代码来源:JsonJacksonFormat.java


注:本文中的com.google.protobuf.UnknownFieldSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。