List of usage examples for org.apache.thrift TFieldRequirementType OPTIONAL
byte OPTIONAL
To view the source code for org.apache.thrift TFieldRequirementType OPTIONAL.
Click Source Link
From source file:com.linecorp.armeria.server.docs.RequirementType.java
License:Apache License
static RequirementType of(byte requirementType) { switch (requirementType) { case TFieldRequirementType.REQUIRED: return RequirementType.REQUIRED; case TFieldRequirementType.OPTIONAL: return RequirementType.OPTIONAL; case TFieldRequirementType.DEFAULT: return RequirementType.DEFAULT; default://from w w w . ja v a 2s .com throw new IllegalArgumentException("unknown requirement type: " + requirementType); } }
From source file:com.linecorp.armeria.server.thrift.ThriftDocServicePlugin.java
License:Apache License
private static FieldRequirement convertRequirement(byte value) { switch (value) { case TFieldRequirementType.REQUIRED: return FieldRequirement.REQUIRED; case TFieldRequirementType.OPTIONAL: return FieldRequirement.OPTIONAL; case TFieldRequirementType.DEFAULT: return FieldRequirement.DEFAULT; default:// w w w. j ava 2 s. c om throw new IllegalArgumentException("unknown requirement type: " + value); } }
From source file:org.apache.avro.thrift.ThriftData.java
License:Apache License
/** Return a record schema given a thrift generated class. */ @SuppressWarnings("unchecked") public Schema getSchema(Class c) { Schema schema = schemaCache.get(c); if (schema == null) { // cache miss try {//from w ww . j a va2 s . c om if (TEnum.class.isAssignableFrom(c)) { // enum List<String> symbols = new ArrayList<String>(); for (Enum e : ((Class<? extends Enum>) c).getEnumConstants()) symbols.add(e.name()); schema = Schema.createEnum(c.getName(), null, null, symbols); } else if (TBase.class.isAssignableFrom(c)) { // struct schema = Schema.createRecord(c.getName(), null, null, Throwable.class.isAssignableFrom(c)); List<Field> fields = new ArrayList<Field>(); for (FieldMetaData f : FieldMetaData.getStructMetaDataMap((Class<? extends TBase>) c) .values()) { Schema s = getSchema(f.valueMetaData); if (f.requirementType == TFieldRequirementType.OPTIONAL && (s.getType() != Schema.Type.UNION)) s = nullable(s); fields.add(new Field(f.fieldName, s, null, null)); } schema.setFields(fields); } else { throw new RuntimeException("Not a Thrift-generated class: " + c); } } catch (Exception e) { throw new RuntimeException(e); } schemaCache.put(c, schema); // update cache } return schema; }