コード例 #1
0
 @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;
 }
コード例 #2
0
 /**
  * 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);
   }
 }
コード例 #3
0
 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();
   }
 }
  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);
  }