@Override public MulticurveProviderDiscount buildObject( final FudgeDeserializer deserializer, final FudgeMsg message) { final Map<Currency, YieldAndDiscountCurve> discountingCurves = new LinkedHashMap<>(); final List<FudgeField> currencyFields = message.getAllByName(CURRENCY_FIELD); final List<FudgeField> discountingCurveFields = message.getAllByName(DISCOUNTING_CURVE_FIELD); for (int i = 0; i < currencyFields.size(); i++) { final Currency currency = Currency.of((String) currencyFields.get(i).getValue()); final YieldAndDiscountCurve curve = deserializer.fudgeMsgToObject( YieldAndDiscountCurve.class, (FudgeMsg) discountingCurveFields.get(i).getValue()); discountingCurves.put(currency, curve); } final Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = new LinkedHashMap<>(); final List<FudgeField> indexIborFields = message.getAllByName(INDEX_IBOR_FIELD); final List<FudgeField> forwardIborCurveFields = message.getAllByName(INDEX_IBOR_CURVE); for (int i = 0; i < currencyFields.size(); i++) { final IborIndex index = deserializer.fudgeMsgToObject( IborIndex.class, (FudgeMsg) indexIborFields.get(i).getValue()); final YieldAndDiscountCurve curve = deserializer.fudgeMsgToObject( YieldAndDiscountCurve.class, (FudgeMsg) forwardIborCurveFields.get(i).getValue()); forwardIborCurves.put(index, curve); } final Map<IndexON, YieldAndDiscountCurve> forwardONCurves = new LinkedHashMap<>(); final List<FudgeField> indexONFields = message.getAllByName(INDEX_ON_FIELD); final List<FudgeField> forwardONCurveFields = message.getAllByName(OVERNIGHT_CURVE_FIELD); for (int i = 0; i < currencyFields.size(); i++) { final IndexON index = deserializer.fudgeMsgToObject( IndexON.class, (FudgeMsg) indexONFields.get(i).getValue()); final YieldAndDiscountCurve curve = deserializer.fudgeMsgToObject( YieldAndDiscountCurve.class, (FudgeMsg) forwardONCurveFields.get(i).getValue()); forwardONCurves.put(index, curve); } final FXMatrix fxMatrix = deserializer.fieldValueToObject(FXMatrix.class, message.getByName(FX_MATRIX_FIELD)); return new MulticurveProviderDiscount( discountingCurves, forwardIborCurves, forwardONCurves, fxMatrix); }
@Override public InflationProviderDiscount buildObject( final FudgeDeserializer deserializer, final FudgeMsg message) { final MulticurveProviderDiscount yieldCurves = deserializer.fieldValueToObject( MulticurveProviderDiscount.class, message.getByName(YIELD_CURVES_FIELD)); final List<FudgeField> indexFields = message.getAllByName(PRICE_INDEX_FIELD); final List<FudgeField> indexCurveFields = message.getAllByName(PRICE_INDEX_CURVE_FIELD); final Map<IndexPrice, PriceIndexCurve> priceIndexCurves = new LinkedHashMap<>(); final int n = indexFields.size(); for (int i = 0; i < n; i++) { final IndexPrice index = deserializer.fudgeMsgToObject( IndexPrice.class, (FudgeMsg) indexFields.get(i).getValue()); final PriceIndexCurve curve = deserializer.fudgeMsgToObject( PriceIndexCurve.class, (FudgeMsg) indexCurveFields.get(i).getValue()); priceIndexCurves.put(index, curve); } return new InflationProviderDiscount(yieldCurves, priceIndexCurves); }
@Override public CalculationJobItem buildObject(FudgeDeserializer deserializer, FudgeMsg message) { ComputationTargetSpecification computationTargetSpecification = deserializer.fudgeMsgToObject(ComputationTargetSpecification.class, message); Validate.notNull( computationTargetSpecification, "Fudge message is not a CalculationJobItem - field 'computationTargetSpecification' is not present"); String functionUniqueId = message.getString(FUNCTION_UNIQUE_ID_FIELD_NAME); Validate.notNull( functionUniqueId, "Fudge message is not a CalculationJobItem - field 'functionUniqueIdentifier' is not present"); FudgeField fudgeField = message.getByName(FUNCTION_PARAMETERS_FIELD_NAME); Validate.notNull( fudgeField, "Fudge message is not a CalculationJobItem - field 'functionParameters' is not present"); FunctionParameters functionParameters = deserializer.fieldValueToObject(FunctionParameters.class, fudgeField); final long[] inputIdentifiers = (long[]) message.getByName(INPUT_FIELD_NAME).getValue(); List<ValueRequirement> desiredValues = new ArrayList<ValueRequirement>(); for (FudgeField field : message.getAllByName(DESIRED_VALUE_FIELD_NAME)) { FudgeMsg valueMsg = (FudgeMsg) field.getValue(); ValueRequirement desiredValue = deserializer.fudgeMsgToObject(ValueRequirement.class, valueMsg); desiredValues.add(desiredValue); } return CalculationJobItem.create( functionUniqueId, functionParameters, computationTargetSpecification, inputIdentifiers, desiredValues); }
public void fudgeEncoding() { List<HistoricalTimeSeriesRatingRule> rules = new ArrayList<HistoricalTimeSeriesRatingRule>(); rules.add(HistoricalTimeSeriesRatingRule.of(DATA_SOURCE_NAME, "BLOOMBERG", 2)); rules.add(HistoricalTimeSeriesRatingRule.of(DATA_SOURCE_NAME, "REUTERS", 1)); rules.add(HistoricalTimeSeriesRatingRule.of(DATA_PROVIDER_NAME, "CMPL", 3)); HistoricalTimeSeriesRating inputConfig = HistoricalTimeSeriesRating.of(rules); FudgeSerializer serializationContext = new FudgeSerializer(s_fudgeContext); MutableFudgeMsg inputMsg = serializationContext.objectToFudgeMsg(inputConfig); FudgeMsg outputMsg = s_fudgeContext.deserialize(s_fudgeContext.toByteArray(inputMsg)).getMessage(); assertNotNull(outputMsg); assertEquals(3, outputMsg.getNumFields()); FudgeDeserializer deserializationContext = new FudgeDeserializer(s_fudgeContext); HistoricalTimeSeriesRating outputConfig = deserializationContext.fudgeMsgToObject(HistoricalTimeSeriesRating.class, outputMsg); assertEquals(inputConfig, outputConfig); }
@Override public Object readFrom( Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { InputStreamReader entityReader = new InputStreamReader(entityStream, Charsets.UTF_8); FudgeMsgReader reader = new FudgeMsgReader(new FudgeJSONStreamReader(getFudgeContext(), entityReader)); FudgeMsg message = reader.nextMessage(); if (message == null) { return null; } FudgeDeserializer deser = new FudgeDeserializer(getFudgeContext()); return deser.fudgeMsgToObject(type, message); }