Package com.google.protobuf.Descriptors

Examples of com.google.protobuf.Descriptors.Descriptor


  /** Internal helper which returns a mutable map. */
  private final Map<FieldDescriptor, Object> getAllFieldsMutable() {
    TreeMap<FieldDescriptor, Object> result =
      new TreeMap<FieldDescriptor, Object>();
    Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
    for (FieldDescriptor field : descriptor.getFields()) {
      if (field.isRepeated()) {
        List value = (List) getField(field);
        if (!value.isEmpty()) {
          result.put(field, value);
        }
View Full Code Here


  private static void mergeField(Tokenizer tokenizer,
                                 ExtensionRegistry extensionRegistry,
                                 Message.Builder builder)
                                 throws ParseException {
    FieldDescriptor field;
    Descriptor type = builder.getDescriptorForType();
    ExtensionRegistry.ExtensionInfo extension = null;

    if (tokenizer.tryConsume("[")) {
      // An extension.
      StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier());
      while (tokenizer.tryConsume(".")) {
        name.append(".");
        name.append(tokenizer.consumeIdentifier());
      }

      extension = extensionRegistry.findExtensionByName(name.toString());

      if (extension == null) {
        throw tokenizer.parseExceptionPreviousToken(
          "Extension \"" + name + "\" not found in the ExtensionRegistry.");
      } else if (extension.descriptor.getContainingType() != type) {
        throw tokenizer.parseExceptionPreviousToken(
          "Extension \"" + name + "\" does not extend message type \"" +
          type.getFullName() + "\".");
      }

      tokenizer.consume("]");

      field = extension.descriptor;
    } else {
      String name = tokenizer.consumeIdentifier();
      field = type.findFieldByName(name);

      // Group names are expected to be capitalized as they appear in the
      // .proto file, which actually matches their type names, not their field
      // names.
      if (field == null) {
        // Explicitly specify US locale so that this code does not break when
        // executing in Turkey.
        String lowerName = name.toLowerCase(Locale.US);
        field = type.findFieldByName(lowerName);
        // If the case-insensitive match worked but the field is NOT a group,
        if (field != null && field.getType() != FieldDescriptor.Type.GROUP) {
          field = null;
        }
      }
      // Again, special-case group names as described above.
      if (field != null && field.getType() == FieldDescriptor.Type.GROUP &&
          !field.getMessageType().getName().equals(name)) {
        field = null;
      }

      if (field == null) {
        throw tokenizer.parseExceptionPreviousToken(
          "Message type \"" + type.getFullName() +
          "\" has no field named \"" + name + "\".");
      }
    }

    Object value = null;
View Full Code Here

        // Invoke the ProtoClass.newBuilder() method
        Object protoBuilder = getCachedMethod(protoClass, "newBuilder")
        .invoke(null);
        Class<?> builderClass = protoBuilder.getClass();

        Descriptor protoDescriptor = (Descriptor) getCachedMethod(
            protoClass, "getDescriptor").invoke(null);
        // Call setters on all of the available fields
        for (FieldDescriptor fieldDescriptor : protoDescriptor.getFields()) {
          String name = fieldDescriptor.getName();
          if (jsonObject.has(name)) {
            JsonElement jsonElement = jsonObject.get(name);
            String fieldName = camelCaseField(name + "_");
            Field field = protoClass.getDeclaredField(fieldName);
View Full Code Here

    if (messagesToIgnore.contains(message.getClass())
        || message.getClass().equals(MessageSet.class)) {
      return;
    }
    Map<Integer, Field> unknownFieldMap = message.getUnknownFields().asMap();
    Descriptor messageDescriptor = message.getDescriptorForType();
    for (Integer unknownTag : unknownFieldMap.keySet()) {
      if (!messageDescriptor.isExtensionNumber(unknownTag)) {
        String fieldName = parentFieldDescriptor == null
            ? "" : parentFieldDescriptor.getName();
        unknownFieldsCollector.add(
            String.format("%s[tag=%d]", fieldName, unknownTag));
      }
View Full Code Here

  private final Map<Descriptor,FieldDescriptor[]> fieldCache =
    new ConcurrentHashMap<Descriptor,FieldDescriptor[]>();

  @Override
  protected Object getRecordState(Object r, Schema s) {
    Descriptor d = ((MessageOrBuilder)r).getDescriptorForType();
    FieldDescriptor[] fields = fieldCache.get(d);
    if (fields == null) {                         // cache miss
      fields = new FieldDescriptor[s.getFields().size()];
      for (Field f : s.getFields())
        fields[f.pos()] = d.findFieldByName(f.name());
      fieldCache.put(d, fields);                  // update cache
    }
    return fields;
  }
View Full Code Here

    }

    public static void serialize(Message src, JsonWriter json) throws IOException {
        ProtobufJsonWriter writer = new ProtobufJsonWriter(json);

        Descriptor descriptor = src.getDescriptorForType();
        MessageMapper mapper = MessageMapper.getMessageMapper(descriptor);
        mapper.write(src, writer);
    }
View Full Code Here

    }

    public void write(Object o) throws IOException {
        if (o instanceof Message) {
            Message message = (Message) o;
            Descriptor descriptor = message.getDescriptorForType();
            MessageMapper mapper = MessageMapper.getMessageMapper(descriptor);
            mapper.write(message, protobuf);
        } else if (o instanceof List) {
            protobuf.beginArray();
            for (Object i : (List) o) {
View Full Code Here

        this.separator = separator;
    }

    public static void serialize(Message src, Writer out, char separator) throws IOException {
        ProtobufPropertiesWriter writer = new ProtobufPropertiesWriter(out, separator);
        Descriptor descriptor = src.getDescriptorForType();
        MessageMapper mapper = MessageMapper.getMessageMapper(descriptor);
        mapper.write(src, writer);
    }
View Full Code Here

        this.out = out;
    }

    public static void serialize(Message src, Writer out) throws IOException {
        ProtobufYamlWriter writer = new ProtobufYamlWriter(out);
        Descriptor descriptor = src.getDescriptorForType();
        MessageMapper mapper = MessageMapper.getMessageMapper(descriptor);
        mapper.write(src, writer);
    }
View Full Code Here

    public static void serialize(List<? extends Message> src, Writer out) throws IOException {
        ProtobufYamlWriter writer = new ProtobufYamlWriter(out);

        for (Message message : src) {
            Descriptor descriptor = message.getDescriptorForType();
            MessageMapper mapper = MessageMapper.getMessageMapper(descriptor);
            mapper.write(message, writer);
        }
    }
View Full Code Here

TOP

Related Classes of com.google.protobuf.Descriptors.Descriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.