@Override public MutableFudgeMsg buildMessage(FudgeSerializer serializer, CalculationJobItem object) { MutableFudgeMsg msg = serializer.newMessage(); ComputationTargetSpecification computationTargetSpecification = object.getComputationTargetSpecification(); if (computationTargetSpecification != null) { MutableFudgeMsg specMsg = serializer.objectToFudgeMsg(computationTargetSpecification); for (FudgeField fudgeField : specMsg.getAllFields()) { msg.add(fudgeField); } } String functionUniqueIdentifier = object.getFunctionUniqueIdentifier(); if (functionUniqueIdentifier != null) { msg.add(FUNCTION_UNIQUE_ID_FIELD_NAME, functionUniqueIdentifier); } FunctionParameters functionParameters = object.getFunctionParameters(); if (functionParameters != null) { serializer.addToMessageWithClassHeaders( msg, FUNCTION_PARAMETERS_FIELD_NAME, null, functionParameters); } long[] inputs = object.getInputIdentifiers(); msg.add(INPUT_FIELD_NAME, inputs); for (ValueRequirement desiredValue : object.getDesiredValues()) { serializer.addToMessage(msg, DESIRED_VALUE_FIELD_NAME, null, desiredValue); } return msg; }
protected void encodeMarketDataAliases( final FudgeSerializer serializer, final MutableFudgeMsg msg, final Map<ValueSpecification, Collection<ValueSpecification>> marketDataEntries) { final MutableFudgeMsg msgRequirements = msg.addSubMessage(MARKET_DATA_REQUIREMENTS_FIELD, null); final MutableFudgeMsg msgAliases = msg.addSubMessage(MARKET_DATA_ALIASES_FIELD, null); for (final Map.Entry<ValueSpecification, Collection<ValueSpecification>> requirement : marketDataEntries.entrySet()) { final ValueSpecification marketData = requirement.getKey(); serializer.addToMessage(msgRequirements, null, null, marketData); if (requirement.getValue().size() == 1) { final ValueSpecification alias = requirement.getValue().iterator().next(); if (alias.equals(marketData)) { msgAliases.add(null, null, IndicatorType.INSTANCE); } else { serializer.addToMessage(msgAliases, null, null, alias); } } else { final MutableFudgeMsg aliases = msgAliases.addSubMessage(null, null); aliases.add(null, 0, "list"); for (ValueSpecification alias : requirement.getValue()) { if (alias.equals(marketData)) { msgAliases.add(null, null, IndicatorType.INSTANCE); } else { serializer.addToMessage(aliases, null, null, alias); } } } } }
public MutableFudgeMsg toFudgeMsg(final FudgeSerializer context) { final MutableFudgeMsg msg = context.newMessage(); for (Map.Entry<ExternalIdBundle, HistoricalTimeSeries> data : _timeSeries.entrySet()) { context.addToMessageWithClassHeaders(msg, null, 1, data.getKey(), ExternalIdBundle.class); context.addToMessageWithClassHeaders( msg, null, 2, data.getValue(), HistoricalTimeSeries.class); } return msg; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final StandardSmileSurfaceDataBundle object) { serializer.addToMessage(message, FORWARD_CURVE_FIELD_NAME, null, object.getForwardCurve()); serializer.addToMessage(message, EXPIRIES_FIELD_NAME, null, object.getExpiries()); serializer.addToMessage(message, STRIKES_FIELD_NAME, null, object.getStrikes()); serializer.addToMessage(message, VOLS_FIELD_NAME, null, object.getVolatilities()); serializer.addToMessage(message, IS_CALL_FIELD_NAME, null, object.isCallData()); }
@Override public MutableFudgeMsg buildMessage( FudgeSerializer serializer, SimpleHistoricalTimeSeries object) { final MutableFudgeMsg message = serializer.newMessage(); if (object.getUniqueId() != null) { serializer.addToMessage(message, UNIQUE_ID_FIELD_NAME, null, object.getUniqueId()); } if (object.getTimeSeries() != null) { serializer.addToMessage(message, TIMESERIES_FIELD_NAME, null, object.getTimeSeries()); } return message; }
@Override public MutableFudgeMsg buildMessage( final FudgeSerializer serializer, final CompiledViewCalculationConfiguration object) { final MutableFudgeMsg msg = serializer.newMessage(); serializer.addToMessage(msg, NAME_FIELD, null, object.getName()); encodeComputationTargets(serializer, msg, object.getComputationTargets()); encodeTerminalOutputSpecifications(serializer, msg, object.getTerminalOutputSpecifications()); encodeMarketDataAliases(serializer, msg, object.getMarketDataAliases()); encodeMarketDataSelections(serializer, msg, object.getMarketDataSelections()); encodeMarketDataFunctionParams( serializer, msg, object.getMarketDataSelectionFunctionParameters()); return msg; }
@Override public MutableFudgeMsg buildMessage( FudgeSerializer serializer, ViewCalculationResultModel resultModel) { final MutableFudgeMsg message = serializer.newMessage(); final Collection<ComputationTargetSpecification> targets = resultModel.getAllTargets(); for (ComputationTargetSpecification target : targets) { final Collection<ComputedValue> values = resultModel.getAllValues(target); for (ComputedValue value : values) { serializer.addToMessage(message, null, null, value); } } return message; }
protected void encodeTerminalOutputSpecifications( final FudgeSerializer serializer, final MutableFudgeMsg msg, final Map<ValueSpecification, Set<ValueRequirement>> outputs) { final MutableFudgeMsg submsg = msg.addSubMessage(TERMINAL_OUTPUT_SPECIFICATIONS_FIELD, null); for (final Map.Entry<ValueSpecification, Set<ValueRequirement>> output : outputs.entrySet()) { serializer.addToMessage(submsg, null, MAP_KEY, output.getKey()); final MutableFudgeMsg submsg2 = submsg.addSubMessage(null, MAP_VALUE); for (final ValueRequirement requirement : output.getValue()) { serializer.addToMessage(submsg2, null, null, requirement); } } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final InflationProviderDiscount object) { serializer.addToMessageWithClassHeaders( message, YIELD_CURVES_FIELD, null, object.getMulticurveProvider()); final Map<IndexPrice, PriceIndexCurve> priceIndexCurves = object.getPriceIndexCurves(); for (final Map.Entry<IndexPrice, PriceIndexCurve> entry : priceIndexCurves.entrySet()) { serializer.addToMessageWithClassHeaders(message, PRICE_INDEX_FIELD, null, entry.getKey()); serializer.addToMessageWithClassHeaders( message, PRICE_INDEX_CURVE_FIELD, null, entry.getValue()); } }
public void toFudgeMsg( final org.fudgemsg.mapping.FudgeSerializer serializer, final org.fudgemsg.MutableFudgeMsg msg) { if (_responses != null) { for (com.opengamma.livedata.msg.EntitlementResponse fudge1 : _responses) { final org.fudgemsg.MutableFudgeMsg fudge2 = org.fudgemsg.mapping.FudgeSerializer.addClassHeader( serializer.newMessage(), fudge1.getClass(), com.opengamma.livedata.msg.EntitlementResponse.class); fudge1.toFudgeMsg(serializer, fudge2); msg.add(RESPONSES_KEY, null, fudge2); } } }
@Override public MutableFudgeMsg buildMessage( final FudgeSerializer serializer, final BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider object) { final MutableFudgeMsg message = serializer.newMessage(); FudgeSerializer.addClassHeader( message, BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider.class); message.add(PREFIX_FIELD_NAME, object.getFutureOptionPrefix()); message.add(POSTFIX_FIELD_NAME, object.getPostfix()); message.add(DATA_FIELD_NAME, object.getDataFieldName()); message.add(CALL_FIELD_NAME, object.useCallAboveStrike()); message.add(EXCHANGE_ID_FIELD_NAME, object.getExchangeIdName()); message.add(TICKER_SCHEME_NAME, object.getSchemeName()); return message; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final CurveBuildingBlockBundle object) { final Map<String, Pair<CurveBuildingBlock, DoubleMatrix2D>> data = object.getData(); for (final Map.Entry<String, Pair<CurveBuildingBlock, DoubleMatrix2D>> entry : data.entrySet()) { message.add(CURVE_NAME_FIELD, entry.getKey()); serializer.addToMessageWithClassHeaders( message, BLOCK_FIELD, null, entry.getValue().getFirst()); serializer.addToMessageWithClassHeaders( message, MATRIX_FIELD, null, entry.getValue().getSecond().getData()); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final FXMatrix object) { final Map<Currency, Integer> currencies = object.getCurrencies(); for (final Map.Entry<Currency, Integer> entry : currencies.entrySet()) { message.add(CURRENCY_FIELD, entry.getKey().getCode()); message.add(ORDER_FIELD, entry.getValue()); } final double[][] rates = object.getRates(); for (final double[] array : rates) { message.add(ENTRIES_FIELD, array.length); final MutableFudgeMsg msg = serializer.newMessage(); serializer.addToMessageWithClassHeaders(msg, ROW_FIELD, null, array); message.add(FX_RATES_FIELD, msg); } }
/** * Builds the message by serializing the specified object. * * <p>This method creates a new message and uses {@link #buildMessage(FudgeSerializer, * MutableFudgeMsg, Object)} to populate it. * * @param serializer the serializer, not null * @param object the object being serialized * @return the created object, not null */ @Override public final MutableFudgeMsg buildMessage(FudgeSerializer serializer, T object) { final MutableFudgeMsg message = serializer.newMessage(); message.add(null, 0, object.getClass().getName()); buildMessage(serializer, message, object); return message; }
public MutableFudgeMsg toFudgeMsg(final FudgeSerializer context) { final MutableFudgeMsg msg = context.newMessage(); for (Map.Entry<String, Entry> entry : _data.entrySet()) { msg.add(entry.getKey(), entry.getValue().toFudgeMsg(context)); } return msg; }
private void testFudgeMessage(final ManageableTrade obj) { final FudgeSerializer serializer = new FudgeSerializer(s_fudgeContext); FudgeMsg msg = serializer.objectToFudgeMsg(obj); s_logger.debug("ManageableTrade {}", obj); s_logger.debug("Encoded to {}", msg); final byte[] bytes = s_fudgeContext.toByteArray(msg); msg = s_fudgeContext.deserialize(bytes).getMessage(); s_logger.debug("Serialised to {}", msg); final ManageableTrade decoded = s_fudgeContext.fromFudgeMsg(ManageableTrade.class, msg); s_logger.debug("Decoded to {}", decoded); if (!obj.equals(decoded)) { s_logger.warn("Expected {}", obj); s_logger.warn("Received {}", decoded); fail(); } }
/** * Adds an object to the specified message if non-null. This handles object hierarchies. * * @param <T> the declared type * @param serializer the serializer, not null * @param msg the msg to populate, not null * @param fieldName the field name, may be null * @param value the value, null ignored * @param declaredType the declared Java type of the field, not null */ protected static <T> void addToMessage( final FudgeSerializer serializer, final MutableFudgeMsg msg, final String fieldName, final T value, final Class<T> declaredType) { if (value != null) { MutableFudgeMsg subMsg = serializer.newMessage(); FudgeSerializer.addClassHeader(subMsg, value.getClass(), declaredType); FudgeMsg builtMsg = serializer.objectToFudgeMsg(value); for (FudgeField field : builtMsg) { subMsg.add(field); } msg.add(fieldName, null, subMsg); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final DoubleMatrix2D object) { serializer.addToMessage(message, DATA_FIELD_NAME, null, object.getData()); }
public static MutableFudgeMsg toFudgeMsg( final FudgeSerializer serializer, final FlexiDateTime object) { if (object == null) { return null; } final MutableFudgeMsg msg = serializer.newMessage(); toFudgeMsg(serializer, object, msg); return msg; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final YieldCurveBundle object) { serializer.addToMessageWithClassHeaders( message, FX_MATRIX_FIELD_NAME, null, object.getFxRates()); for (final String curve : object.getAllNames()) { serializer.addToMessageWithClassHeaders( message, CURVES_FIELD_NAME, null, object.getCurve(curve)); serializer.addToMessageWithClassHeaders(message, CURVES_NAME_FIELD_NAME, null, curve); } for (Map.Entry<String, Currency> ccyEntry : object.getCurrencyMap().entrySet()) { serializer.addToMessage(message, CURRENCY_CURVE_FIELD_NAME, null, ccyEntry.getKey()); serializer.addToMessageWithClassHeaders( message, CURRENCY_FIELD_NAME, null, ccyEntry.getValue()); } }
protected void encodeComputationTargets( final FudgeSerializer serializer, final MutableFudgeMsg msg, final Set<ComputationTargetSpecification> targets) { final MutableFudgeMsg submsg = msg.addSubMessage(COMPUTATION_TARGETS_FIELD, null); for (final ComputationTargetSpecification target : targets) { serializer.addToMessage(submsg, null, null, target); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final DoubleLabelledMatrix1D object) { final MutableFudgeMsg msg = serializer.newMessage(); final Double[] keys = object.getKeys(); final Object[] labels = object.getLabels(); final double[] values = object.getValues(); for (int i = 0; i < object.size(); i++) { msg.add(LABEL_TYPE_ORDINAL, labels[i].getClass().getName()); msg.add(KEY_ORDINAL, keys[i]); serializer.addToMessage(msg, null, LABEL_ORDINAL, labels[i]); msg.add(VALUE_ORDINAL, values[i]); } message.add(MATRIX_FIELD_NAME, msg); }
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); }
/** * Adds an object to the specified message if non-null. * * @param <T> the declared type * @param msg the msg to populate, not null * @param fieldName the field name, may be null * @param objectMsg the object converted to a message, null ignored * @param value the value, null ignored * @param declaredType the declared Java type of the field, not null */ protected static <T> void addToMessage( final MutableFudgeMsg msg, final String fieldName, final FudgeMsg objectMsg, final T value, final Class<T> declaredType) { if (objectMsg != null) { FudgeSerializer.addClassHeader((MutableFudgeMsg) objectMsg, value.getClass(), declaredType); msg.add(fieldName, null, objectMsg); } }
protected static MutableFudgeMsg buildMessageImpl( final FudgeSerializer serializer, final Position position) { final MutableFudgeMsg message = serializer.newMessage(); if (position.getUniqueId() != null) { serializer.addToMessage(message, FIELD_UNIQUE_ID, null, position.getUniqueId()); } if (position.getQuantity() != null) { message.add(FIELD_QUANTITY, null, position.getQuantity()); } if (position.getSecurityLink().getExternalId().size() > 0) { serializer.addToMessage( message, FIELD_SECURITYKEY, null, position.getSecurityLink().getExternalId()); } if (position.getSecurityLink().getObjectId() != null) { serializer.addToMessage( message, FIELD_SECURITYID, null, position.getSecurityLink().getObjectId()); } encodeTrades(message, serializer, position.getTrades()); return message; }
private static void encodeTrades( final MutableFudgeMsg message, final FudgeSerializer serializer, final Collection<Trade> trades) { if (!trades.isEmpty()) { final MutableFudgeMsg msg = serializer.newMessage(); for (Trade trade : trades) { msg.add(null, null, TradeBuilder.buildMessageImpl(serializer, trade)); } message.add(FIELD_TRADES, msg); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final StringLabelledMatrix1D object) { final MutableFudgeMsg msg = serializer.newMessage(); final String[] keys = object.getKeys(); final double[] values = object.getValues(); for (int i = 0; i < object.size(); i++) { msg.add(KEY_ORDINAL, keys[i]); msg.add(VALUE_ORDINAL, values[i]); } message.add(MATRIX_FIELD_NAME, msg); }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final MulticurveProviderDiscount object) { final Map<Currency, YieldAndDiscountCurve> discountingCurves = object.getDiscountingCurves(); for (final Map.Entry<Currency, YieldAndDiscountCurve> entry : discountingCurves.entrySet()) { message.add(CURRENCY_FIELD, entry.getKey().getCode()); serializer.addToMessageWithClassHeaders( message, DISCOUNTING_CURVE_FIELD, null, entry.getValue()); } final Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = object.getForwardIborCurves(); for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry : forwardIborCurves.entrySet()) { serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_FIELD, null, entry.getKey()); serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_CURVE, null, entry.getValue()); } final Map<IndexON, YieldAndDiscountCurve> forwardONCurves = object.getForwardONCurves(); for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry : forwardONCurves.entrySet()) { serializer.addToMessageWithClassHeaders(message, INDEX_ON_FIELD, null, entry.getKey()); serializer.addToMessageWithClassHeaders( message, OVERNIGHT_CURVE_FIELD, null, entry.getValue()); } serializer.addToMessageWithClassHeaders(message, FX_MATRIX_FIELD, null, object.getFxRates()); }
public MutableFudgeMsg toFudgeMsg(final FudgeSerializer serializer) { final MutableFudgeMsg msg = serializer.newMessage(); msg.add("structureId", _structureId); return msg; }
@Override public MutableFudgeMsg buildMessage(FudgeSerializer serializer, EquitySecurity object) { final MutableFudgeMsg msg = serializer.newMessage(); EquitySecurityFudgeBuilder.toFudgeMsg(serializer, object, msg); return msg; }