use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.
the class PdlSchemaParser method parseFixed.
private FixedDataSchema parseFixed(NamedTypeDeclarationContext context, FixedDeclarationContext fixed) throws ParseException {
Name name = toName(fixed.name);
FixedDataSchema schema = new FixedDataSchema(name);
bindNameToSchema(name, schema);
schema.setSize(fixed.size, errorMessageBuilder());
setProperties(context, schema);
return schema;
}
use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.
the class TestSchemaSampleDataGenerator method testFixedSchema.
@Test
public void testFixedSchema() {
final FixedDataSchema schema = (FixedDataSchema) DataTemplateUtil.getSchema(FixedMD5.class);
final ByteString value = (ByteString) SchemaSampleDataGenerator.buildData(schema, _spec);
Assert.assertSame(value.length(), schema.getSize());
}
use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.
the class TemplateSpecGenerator method generateNamedSchema.
private ClassTemplateSpec generateNamedSchema(NamedDataSchema schema) {
pushCurrentLocation(_schemaResolver.nameToDataSchemaLocations().get(schema.getFullName()));
// make sure no duplicate template spec classname which should be binding name of the schema
final String className = schema.getBindingName();
checkForClassNameConflict(className, schema);
final ClassTemplateSpec templateClass;
switch(schema.getType()) {
case RECORD:
templateClass = generateRecord((RecordDataSchema) schema);
break;
case ENUM:
templateClass = generateEnum((EnumDataSchema) schema);
break;
case FIXED:
templateClass = generateFixed((FixedDataSchema) schema);
break;
default:
throw unrecognizedSchemaType(null, null, schema);
}
popCurrentLocation();
return templateClass;
}
use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method generateFieldDefValue.
private Object generateFieldDefValue(FieldDef<?> fieldDef) {
Object value = _dataGenerator.buildData(fieldDef.getName(), fieldDef.getDataSchema());
DataSchema dereferencedDataSchema = fieldDef.getDataSchema().getDereferencedDataSchema();
if (!dereferencedDataSchema.isPrimitive()) {
switch(dereferencedDataSchema.getType()) {
case FIXED:
value = new FixedTemplatePlaceholder(value, (FixedDataSchema) dereferencedDataSchema);
break;
case ENUM:
// just use the string value already generated. Will be coerced by DataTemplateUtil.DynamicEnumCoercer.
break;
case ARRAY:
value = new ArrayTemplatePlaceholder<Object>((DataList) value, (ArrayDataSchema) dereferencedDataSchema, Object.class);
break;
case RECORD:
value = new RecordTemplatePlaceholder((DataMap) value, (RecordDataSchema) dereferencedDataSchema);
break;
case MAP:
value = new MapTemplatePlaceholder<Object>((DataMap) value, (MapDataSchema) dereferencedDataSchema, Object.class);
break;
case UNION:
value = new UnionTemplatePlaceholder(value, (UnionDataSchema) dereferencedDataSchema);
break;
case TYPEREF:
throw new IllegalStateException("TYPEREF should not be returned for a dereferenced byte. schema: " + fieldDef.getDataSchema());
default:
throw new IllegalStateException("Unrecognized enum value: " + dereferencedDataSchema.getType());
}
}
return value;
}
use of com.linkedin.data.schema.FixedDataSchema in project rest.li by linkedin.
the class CompatibilityChecker method check.
private void check(DataSchema older, DataSchema newer) {
Checked toCheck = new Checked(older, newer);
if (_checked.contains(toCheck)) {
return;
}
_checked.add(toCheck);
if (older == newer) {
return;
}
int pathCount = 1;
if (_options.getMode() == CompatibilityOptions.Mode.DATA) {
older = older.getDereferencedDataSchema();
while (newer.getType() == DataSchema.Type.TYPEREF) {
TyperefDataSchema typerefDataSchema = ((TyperefDataSchema) newer);
_path.addLast(typerefDataSchema.getFullName());
_path.addLast(DataSchemaConstants.REF_KEY);
pathCount++;
newer = typerefDataSchema.getRef();
}
}
if (newer.getType() == DataSchema.Type.TYPEREF) {
_path.addLast(((TyperefDataSchema) newer).getFullName());
} else {
_path.addLast(newer.getUnionMemberKey());
}
switch(newer.getType()) {
case TYPEREF:
if (isSameType(older, newer))
checkTyperef((TyperefDataSchema) older, (TyperefDataSchema) newer);
break;
case RECORD:
if (isSameType(older, newer))
checkRecord((RecordDataSchema) older, (RecordDataSchema) newer);
break;
case ARRAY:
if (isSameType(older, newer))
checkArray((ArrayDataSchema) older, (ArrayDataSchema) newer);
break;
case MAP:
if (isSameType(older, newer))
checkMap((MapDataSchema) older, (MapDataSchema) newer);
break;
case ENUM:
if (isSameType(older, newer))
checkEnum((EnumDataSchema) older, (EnumDataSchema) newer);
break;
case FIXED:
if (isSameType(older, newer))
checkFixed((FixedDataSchema) older, (FixedDataSchema) newer);
break;
case UNION:
if (isSameType(older, newer))
checkUnion((UnionDataSchema) older, (UnionDataSchema) newer);
break;
default:
if (newer instanceof PrimitiveDataSchema)
checkPrimitive(older, newer);
else
throw new IllegalStateException("Unknown schema type " + newer.getType() + ", checking old schema " + older + ", new schema " + newer);
break;
}
for (; pathCount > 0; pathCount--) {
_path.removeLast();
}
return;
}
Aggregations