Beispiel #1
0
 /**
  * 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;
 }
 @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;
 }
 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;
 }
 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;
 }
 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;
 }
 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
 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;
 }
Beispiel #9
0
 @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;
 }
 @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
 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;
 }
 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
 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);
   }
 }
 /**
  * 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 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);
    }
 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;
 }
 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;
 }
 public org.fudgemsg.FudgeMsg toFudgeMsg(final org.fudgemsg.mapping.FudgeSerializer serializer) {
   if (serializer == null) throw new NullPointerException("serializer must not be null");
   final org.fudgemsg.MutableFudgeMsg msg = serializer.newMessage();
   toFudgeMsg(serializer, msg);
   return msg;
 }
 // -------------------------------------------------------------------------
 @Override
 public MutableFudgeMsg buildMessage(FudgeSerializer serializer, FlexiDateTime object) {
   final MutableFudgeMsg msg = serializer.newMessage();
   toFudgeMsg(serializer, object, msg);
   return msg;
 }
Beispiel #21
0
  @Override
  public MutableFudgeMsg buildMessage(FudgeSerializer serializer, final T auto) {
    MutableFudgeMsg outerMsg = serializer.newMessage();
    outerMsg.add(
        null,
        FudgeSerializer.TYPES_HEADER_ORDINAL,
        FudgeWireType.STRING,
        AutoFudgable.class.getName());
    final K inner = auto.object();
    assertValid(inner.getClass());
    try {
      MutableFudgeMsg msg = outerMsg.addSubMessage("inner", null);
      // save the internal class name
      msg.add(
          null,
          FudgeSerializer.TYPES_HEADER_ORDINAL,
          FudgeWireType.STRING,
          inner.getClass().getName());

      // save the ctor parameters
      List<Object> parameters =
          AccessController.doPrivileged(
              new PrivilegedAction<List<Object>>() {
                @Override
                public List<Object> run() {
                  try {
                    final Constructor<?>[] ctors = inner.getClass().getDeclaredConstructors();
                    // We require that inner classes got only one ctor (anonymous inner classes will
                    // do)
                    // in order to avoid disambiguity
                    if (ctors.length == 1) {
                      final Constructor<?> ctor = ctors[0];
                      // types of parameters of ctor
                      final Class<?>[] parameterTypes = ctor.getParameterTypes();
                      // all declared parameters of the inner class
                      final Field[] fs = inner.getClass().getDeclaredFields();
                      // extracting copiler synthetized fields of inner class
                      // first are the not sinthetized fields (regular ones) we need to skip
                      // then there are compiler synthetized fields with corresponds to ctor
                      // parameters
                      // the last field is the reference to enclosing object so we need to skipp it
                      // as well
                      final Field[] paramFields =
                          Arrays.copyOfRange(fs, fs.length - parameterTypes.length, fs.length - 1);
                      final List<Object> parameters = newArrayList();
                      for (Field paramField : paramFields) {
                        paramField.setAccessible(true);
                        parameters.add(paramField.get(inner));
                      }
                      return parameters;
                    }
                  } catch (IllegalAccessException e) {
                    // Ignore
                  }
                  return null;
                }
              });

      for (Object parameter : parameters) {
        // save the ctor parameter
        serializer.addToMessageWithClassHeaders(msg, null, 1, parameter);
      }
      return outerMsg;

    } catch (RuntimeException ex) {
      throw new FudgeRuntimeException("Unable to serialize: " + inner.getClass().getName(), ex);
    }
  }
Beispiel #22
0
 public MutableFudgeMsg toFudgeMsg(final FudgeSerializer serializer) {
   MutableFudgeMsg msg = serializer.newMessage();
   serializer.addToMessage(msg, SCALING_FACTOR, null, _scalingFactor);
   return msg;
 }