com.google.protobuf.Descriptors.OneofDescriptor Java Examples

The following examples show how to use com.google.protobuf.Descriptors.OneofDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OneofTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testFieldOrder() throws Exception {
  Descriptor descriptor = OneofMsg.getDescriptor();
  List<FieldDescriptor> fields = descriptor.getFields();
  assertEquals(3, fields.get(0).getNumber());
  assertEquals(2, fields.get(1).getNumber());
  assertEquals(5, fields.get(2).getNumber());
  assertEquals(6, fields.get(3).getNumber());
  assertEquals(4, fields.get(4).getNumber());
  assertEquals(1, fields.get(5).getNumber());

  OneofDescriptor oneof = descriptor.getOneofs().get(0);
  List<FieldDescriptor> oneofFields = oneof.getFields();
  assertEquals(6, oneofFields.get(0).getNumber());
  assertEquals(4, oneofFields.get(1).getNumber());
  assertEquals(1, oneofFields.get(2).getNumber());

  assertEquals(oneof, fields.get(3).getContainingOneof());
  assertEquals(oneof, fields.get(4).getContainingOneof());
  assertEquals(oneof, fields.get(5).getContainingOneof());
}
 
Example #2
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public Builder setField(FieldDescriptor field, Object value) {
  verifyContainingType(field);
  ensureIsMutable();
  // TODO(xiaofeng): This check should really be put in FieldSet.setField()
  // where all other such checks are done. However, currently
  // FieldSet.setField() permits Integer value for enum fields probably
  // because of some internal features we support. Should figure it out
  // and move this check to a more appropriate place.
  if (field.getType() == FieldDescriptor.Type.ENUM) {
    ensureEnumValueDescriptor(field, value);
  }
  OneofDescriptor oneofDescriptor = field.getContainingOneof();
  if (oneofDescriptor != null) {
    int index = oneofDescriptor.getIndex();
    FieldDescriptor oldField = oneofCases[index];
    if ((oldField != null) && (oldField != field)) {
      fields.clearField(oldField);
    }
    oneofCases[index] = field;
  }
  fields.setField(field, value);
  return this;
}
 
Example #3
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Builder setField(FieldDescriptor field, Object value) {
  verifyContainingType(field);
  ensureIsMutable();
  // TODO(xiaofeng): This check should really be put in FieldSet.setField()
  // where all other such checks are done. However, currently
  // FieldSet.setField() permits Integer value for enum fields probably
  // because of some internal features we support. Should figure it out
  // and move this check to a more appropriate place.
  if (field.getType() == FieldDescriptor.Type.ENUM) {
    ensureEnumValueDescriptor(field, value);
  }
  OneofDescriptor oneofDescriptor = field.getContainingOneof();
  if (oneofDescriptor != null) {
    int index = oneofDescriptor.getIndex();
    FieldDescriptor oldField = oneofCases[index];
    if ((oldField != null) && (oldField != field)) {
      fields.clearField(oldField);
    }
    oneofCases[index] = field;
  }
  fields.setField(field, value);
  return this;
}
 
Example #4
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public boolean hasOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field == null) {
    return false;
  }
  return true;
}
 
Example #5
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Verifies that the oneof is an oneof of this message. */
private void verifyOneofContainingType(OneofDescriptor oneof) {
  if (oneof.getContainingType() != type) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
}
 
Example #6
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public boolean hasOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field == null) {
    return false;
  }
  return true;
}
 
Example #7
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public Builder clearOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field != null) {
    clearField(field);
  }
  return this;
}
 
Example #8
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public Builder clearField(FieldDescriptor field) {
  verifyContainingType(field);
  ensureIsMutable();
  OneofDescriptor oneofDescriptor = field.getContainingOneof();
  if (oneofDescriptor != null) {
    int index = oneofDescriptor.getIndex();
    if (oneofCases[index] == field) {
      oneofCases[index] = null;
    }
  }
  fields.clearField(field);
  return this;
}
 
Example #9
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Verifies that the oneof is an oneof of this message. */
private void verifyOneofContainingType(OneofDescriptor oneof) {
  if (oneof.getContainingType() != type) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
}
 
Example #10
Source File: GeneratedMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
/** Get the OneofAccessor for a particular oneof. */
private OneofAccessor getOneof(final OneofDescriptor oneof) {
  if (oneof.getContainingType() != descriptor) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
  return oneofs[oneof.getIndex()];
}
 
Example #11
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Get the OneofAccessor for a particular oneof. */
private OneofAccessor getOneof(final OneofDescriptor oneof) {
  if (oneof.getContainingType() != descriptor) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
  return oneofs[oneof.getIndex()];
}
 
Example #12
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean hasOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field == null) {
    return false;
  }
  return true;
}
 
Example #13
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
/** Verifies that the oneof is an oneof of this message. */
private void verifyOneofContainingType(OneofDescriptor oneof) {
  if (oneof.getContainingType() != type) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
}
 
Example #14
Source File: OneofTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testOneofDescriptor() throws Exception {
  Descriptor descriptor = OneofMsg.getDescriptor();
  List<OneofDescriptor> oneofs = descriptor.getOneofs();
  assertEquals(1, oneofs.size());
  OneofDescriptor oneof = oneofs.get(0);
  assertEquals("oneof_group", oneof.getName());
  assertEquals(descriptor, oneof.getContainingType());
}
 
Example #15
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
/** Verifies that the oneof is an oneof of this message. */
private void verifyOneofContainingType(OneofDescriptor oneof) {
  if (oneof.getContainingType() != type) {
    throw new IllegalArgumentException(
      "OneofDescriptor does not match message type.");
  }
}
 
Example #16
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Builder clearField(FieldDescriptor field) {
  verifyContainingType(field);
  ensureIsMutable();
  OneofDescriptor oneofDescriptor = field.getContainingOneof();
  if (oneofDescriptor != null) {
    int index = oneofDescriptor.getIndex();
    if (oneofCases[index] == field) {
      oneofCases[index] = null;
    }
  }
  fields.clearField(field);
  return this;
}
 
Example #17
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean hasOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field == null) {
    return false;
  }
  return true;
}
 
Example #18
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Builder clearOneof(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  FieldDescriptor field = oneofCases[oneof.getIndex()];
  if (field != null) {
    clearField(field);
  }
  return this;
}
 
Example #19
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
  return internalGetFieldAccessorTable().getOneof(oneof).get(this);
}
 
Example #20
Source File: XMessage.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor arg0) {
    return this.message.getOneofFieldDescriptor(arg0);
}
 
Example #21
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
  verifyOneofContainingType(oneof);
  return oneofCases[oneof.getIndex()];
}
 
Example #22
Source File: AbstractMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public BuilderType clearOneof(OneofDescriptor oneof) {
  throw new UnsupportedOperationException("clearOneof() is not implemented.");
}
 
Example #23
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public boolean hasOneof(final OneofDescriptor oneof) {
  return internalGetFieldAccessorTable().getOneof(oneof).has(this);
}
 
Example #24
Source File: AbstractMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
  throw new UnsupportedOperationException(
      "getOneofFieldDescriptor() is not implemented.");
}
 
Example #25
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public boolean hasOneof(final OneofDescriptor oneof) {
  return internalGetFieldAccessorTable().getOneof(oneof).has(this);
}
 
Example #26
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
  return internalGetFieldAccessorTable().getOneof(oneof).get(this);
}
 
Example #27
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public BuilderType clearOneof(final OneofDescriptor oneof) {
  internalGetFieldAccessorTable().getOneof(oneof).clear(this);
  return (BuilderType) this;
}
 
Example #28
Source File: AbstractMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public boolean hasOneof(OneofDescriptor oneof) {
  throw new UnsupportedOperationException("hasOneof() is not implemented.");
}
 
Example #29
Source File: AbstractMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
  throw new UnsupportedOperationException(
      "getOneofFieldDescriptor() is not implemented.");
}
 
Example #30
Source File: AbstractMessage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** TODO(jieluo): Clear it when all subclasses have implemented this method. */
@Override
public boolean hasOneof(OneofDescriptor oneof) {
  throw new UnsupportedOperationException("hasOneof() is not implemented.");
}