Tabnine Logo
ThriftFieldMetadata.getId
Code IndexAdd Tabnine to your IDE (free)

How to use
getId
method
in
com.facebook.swift.codec.metadata.ThriftFieldMetadata

Best Java code snippets using com.facebook.swift.codec.metadata.ThriftFieldMetadata.getId (Showing top 20 results out of 315)

origin: com.gitee.l0km/common-swift-metadata

  @Override
  public Short apply(ThriftFieldMetadata input)
  {
    return input.getId();
  }
}));
origin: com.facebook.swift/swift-codec

  @Override
  public Short apply(ThriftFieldMetadata input)
  {
    return input.getId();
  }
}));
origin: com.gitee.l0km/common-swift-metadata

  @Override
  public Short apply(ThriftFieldMetadata metadata)
  {
    return metadata.getId();
  }
};
origin: com.facebook.swift/swift-codec

  @Override
  public Short apply(ThriftFieldMetadata metadata)
  {
    return metadata.getId();
  }
};
origin: com.facebook.swift/swift-codec

/**
 * Defines the code to inject data into the struct public fields.
 */
private void injectStructFields(MethodDefinition read, LocalVariableDefinition instance, Map<Short, LocalVariableDefinition> structData)
{
  for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
    injectField(read, field, instance, structData.get(field.getId()));
  }
}
origin: com.facebook.swift/swift-codec

@Override
public void write(T instance, TProtocol protocol)
    throws Exception
{
  TProtocolWriter writer = new TProtocolWriter(protocol);
  Short idValue = (Short) getFieldValue(instance, idField.getKey());
  writer.writeStructBegin(metadata.getStructName());
  if (metadataMap.containsKey(idValue)) {
    ThriftFieldMetadata fieldMetadata = metadataMap.get(idValue);
    if (fieldMetadata.isReadOnly() || fieldMetadata.getType() != THRIFT_FIELD) {
      throw new IllegalStateException(format("Field %s is not readable", fieldMetadata.getName()));
    }
    Object fieldValue = getFieldValue(instance, fieldMetadata);
    // write the field
    if (fieldValue != null) {
      @SuppressWarnings("unchecked")
      ThriftCodec<Object> codec = (ThriftCodec<Object>) fields.get(fieldMetadata.getId());
      writer.writeField(fieldMetadata.getName(), fieldMetadata.getId(), codec, fieldValue);
    }
  }
  writer.writeStructEnd();
}
origin: com.gitee.l0km/common-thrift

  data.put(field.getId(), value);
} catch (Exception e) {
  Throwables.throwIfUnchecked(e);
origin: com.gitee.l0km/common-thrift

for (ThriftFieldMetadata fieldMetadata : methodMetadata.getParameters()) {
  @SuppressWarnings("unused")
  Builder<Short, ThriftCodec<?>> p = builder.put(fieldMetadata.getId(), codecManager.getCodec(fieldMetadata.getThriftType()));
for (ThriftFieldMetadata fieldMetadata : methodMetadata.getParameters()) {
  @SuppressWarnings("unused")
  Builder<Short, Short> p = parameterOrderingBuilder.put(fieldMetadata.getId(), javaArgumentPosition++);
origin: com.facebook.swift/swift-codec

@Override
public void write(T instance, TProtocol protocol)
    throws Exception
{
  TProtocolWriter writer = new TProtocolWriter(protocol);
  writer.writeStructBegin(metadata.getStructName());
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields(THRIFT_FIELD)) {
    // is the field readable?
    if (fieldMetadata.isWriteOnly()) {
      continue;
    }
    // get the field value
    Object fieldValue = getFieldValue(instance, fieldMetadata);
    // write the field
    if (fieldValue != null) {
      @SuppressWarnings("unchecked")
      ThriftCodec<Object> codec = (ThriftCodec<Object>) fields.get(fieldMetadata.getId());
      writer.writeField(fieldMetadata.getName(), fieldMetadata.getId(), codec, fieldValue);
    }
  }
  writer.writeStructEnd();
}
origin: com.gitee.l0km/common-thrifty

DecoratorThriftFieldMetadata(ThriftFieldMetadata input){
  super(
      input.getId(),
      input.getRequiredness(),
      input.getThriftType(),
      input.getName(),
      input.getType(),
      input.getInjections(),
      input.getConstructorInjection(),
      input.getMethodInjection(),
      input.getExtraction(),
      input.getCoercion());
  // 获取field的类型
  List<ThriftInjection> injections = getInjections();
  checkState(injections.size()>0,"invalid size of injections");
  ThriftInjection injection = injections.get(0);		
  if(injection instanceof ThriftParameterInjection){
    javaType = ((ThriftParameterInjection)injection).getJavaType();
  }else if(injection instanceof ThriftFieldInjection){
    javaType = ((ThriftFieldInjection)injection).getField().getType();
  }else{
    javaType = null;
    // 对于不支持的数据类型无法获取field类型,输出警告
    logger.warning(
        String.format("UNSUPPORED TYPE %s,can't get Java Type. "
            + "(不识别的ThriftInjection实例类型,无法实现requiredness转义)",
        null == injection? null : injection.getClass().getName()));
  }
}
/** 重载方法,实现 requiredness 转义 */
origin: com.gitee.l0km/common-thrift

public DecoratorThriftFieldMetadata(ThriftFieldMetadata input){
  super(
      input.getId(),
      input.getRequiredness(),
      input.getThriftType(),
      input.getName(),
      input.getType(),
      input.getInjections(),
      input.getConstructorInjection(),
      input.getMethodInjection(),
      input.getExtraction(),
      input.getCoercion());
  // 获取field的类型
  List<ThriftInjection> injections = getInjections();
  checkState(injections.size()>0,"invalid size of injections");
  ThriftInjection injection = injections.get(0);		
  if(injection instanceof ThriftParameterInjection){
    javaType = ((ThriftParameterInjection)injection).getJavaType();
  }else if(injection instanceof ThriftFieldInjection){
    javaType = ((ThriftFieldInjection)injection).getField().getType();
  }else{
    javaType = null;
    // 对于不支持的数据类型无法获取field类型,输出警告
    logger.warning(
        String.format("UNSUPPORED TYPE %s,can't get Java Type. "
            + "(不识别的ThriftInjection实例类型,无法实现requiredness转义)",
        null == injection? null : injection.getClass().getName()));
  }
}
/** 重载方法,实现 requiredness 转义 */
origin: com.facebook.swift/swift-codec

/**
 * Declares a field for each delegate codec
 *
 * @return a map from field id to the codec for the field
 */
private Map<Short, FieldDefinition> declareCodecFields()
{
  Map<Short, FieldDefinition> codecFields = new TreeMap<>();
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields()) {
    if (needsCodec(fieldMetadata)) {
      ThriftCodec<?> codec = codecManager.getCodec(fieldMetadata.getThriftType());
      String fieldName = fieldMetadata.getName() + "Codec";
      FieldDefinition codecField = new FieldDefinition(a(PRIVATE, FINAL), fieldName, type(codec.getClass()));
      classDefinition.addField(codecField);
      codecFields.put(fieldMetadata.getId(), codecField);
      parameters.add(codecField, codec);
    }
  }
  return codecFields;
}
origin: com.facebook.swift/swift-codec

protected AbstractReflectionThriftCodec(ThriftCodecManager manager, ThriftStructMetadata metadata)
{
  this.metadata = metadata;
  ImmutableSortedMap.Builder<Short, ThriftCodec<?>> fields = ImmutableSortedMap.naturalOrder();
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields(THRIFT_FIELD)) {
    fields.put(fieldMetadata.getId(), manager.getCodec(fieldMetadata.getThriftType()));
  }
  this.fields = fields.build();
}
origin: com.facebook.swift/swift-codec

  private <T> void verifyField(ThriftStructMetadata metadata, int id, String name)
  {
    ThriftFieldMetadata messageField = metadata.getField(id);
    assertNotNull(messageField, "field '" + name + "' is null");
    assertEquals(messageField.getId(), id);
    assertEquals(messageField.getName(), name);
    assertFalse(messageField.isReadOnly());
    assertFalse(messageField.isWriteOnly());

    assertTrue(messageField.getExtraction().isPresent());
    ThriftExtraction extraction = messageField.getExtraction().get();
    assertEquals(extraction.getId(), id);
    assertEquals(extraction.getName(), name);

    assertNotNull(messageField.getInjections());
    assertEquals(messageField.getInjections().size(), 1);
    ThriftInjection injection = messageField.getInjections().get(0);
    assertEquals(injection.getId(), id);
    assertEquals(injection.getName(), name);
  }
}
origin: com.facebook.swift/swift-codec

cases.add(caseStatement(field.getId(), field.getName() + "-inject-field"));
injectField(read, field, instance, unionData.get(field.getId()));
origin: com.facebook.swift/swift-codec

  private <T> void verifyField(ThriftStructMetadata metadata, int id, String name)
  {
    ThriftFieldMetadata metadataField = metadata.getField(id);
    assertNotNull(metadataField, "metadataField is null");
    assertEquals(metadataField.getId(), id);
    assertEquals(metadataField.getName(), name);
    assertFalse(metadataField.isReadOnly());
    assertFalse(metadataField.isWriteOnly());

    assertTrue(metadataField.getExtraction().isPresent());
    ThriftExtraction extraction = metadataField.getExtraction().get();
    assertEquals(extraction.getId(), id);
    assertEquals(extraction.getName(), name);

    assertNotNull(metadataField.getInjections());
    assertEquals(metadataField.getInjections().size(), 1);
    ThriftInjection injection = metadataField.getInjections().get(0);
    assertEquals(injection.getId(), id);
    assertEquals(injection.getName(), name);
  }
}
origin: com.facebook.swift/swift-codec

@Test
public void testLegacyIdCorrectlyAnnotated()
{
  ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), LegacyIdCorrect.class);
  ThriftStructMetadata metadata = builder.build();
  Set<Integer> seen = new HashSet<>();
  for (ThriftFieldMetadata field : metadata.getFields()) {
    seen.add((int) field.getId());
  }
  assertThat(seen)
      .as("fields found in LegacyIdCorrect")
      .isEqualTo(LegacyIdCorrect.IDS);
}
origin: com.facebook.swift/swift-codec

@Test
public void testLegacyIdOnUnion()
{
  ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), LegacyIdUnionCorrect.class);
  ThriftStructMetadata metadata = builder.build();
  Set<Integer> seen = new HashSet<>();
  for (ThriftFieldMetadata field : metadata.getFields()) {
    seen.add((int) field.getId());
  }
  assertThat(seen)
      .as("fields found in LegacyIdUnionCorrect")
      .isEqualTo(LegacyIdUnionCorrect.IDS);
}
origin: com.facebook.swift/swift-service

@Test(dataProvider="getTestCasesWithLegacyFieldIds")
public void testLegacyFieldIds(Method[] mBox)
{
  Method m = mBox[0];
  ThriftMethodMetadata metadata = new ThriftMethodMetadata("DummyService", m, new ThriftCatalog());
  List<ThriftFieldMetadata> parameters = metadata.getParameters();
  assertThat(parameters)
      .as("parameters")
      .hasSize(1);
  assertThat(parameters.get(0).getId())
      .as("the parameter's ID")
      .isNegative();
}
origin: com.facebook.swift/swift-service

@Test(dataProvider="getTestCasesWithNonLegacyFieldIds")
public void testNonLegacyFieldIds(Method[] mBox)
{
  Method m = mBox[0];
  ThriftMethodMetadata metadata = new ThriftMethodMetadata("DummyService", m, new ThriftCatalog());
  List<ThriftFieldMetadata> parameters = metadata.getParameters();
  assertThat(parameters)
      .as("parameters")
      .hasSize(1);
  assertThat(parameters.get(0).getId())
      .as("the parameter's ID")
      .isGreaterThanOrEqualTo((short) 0);
}
com.facebook.swift.codec.metadataThriftFieldMetadatagetId

Popular methods of ThriftFieldMetadata

  • getName
  • getRequiredness
  • getThriftType
  • getConstructorInjection
  • getExtraction
  • getInjections
  • getType
  • isWriteOnly
  • getCoercion
  • getMethodInjection
  • <init>
  • isReadOnly
  • <init>,
  • isReadOnly,
  • isTypePredicate,
  • getIdGetter,
  • getIdlAnnotations,
  • isRecursiveReference,
  • isTypeReferenceRecursive

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • findViewById (Activity)
  • getExternalFilesDir (Context)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now