protected Map<ValueSpecification, Collection<ValueSpecification>> decodeMarketDataAliases(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg msgRequirements = msg.getMessage(MARKET_DATA_REQUIREMENTS_FIELD);
   final FudgeMsg msgAliases = msg.getMessage(MARKET_DATA_ALIASES_FIELD);
   if ((msgRequirements == null) || (msgAliases == null) || msgRequirements.isEmpty()) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Collection<ValueSpecification>> result =
       Maps.newHashMapWithExpectedSize(msgRequirements.getNumFields());
   final Iterator<FudgeField> itrRequirements = msgRequirements.iterator();
   final Iterator<FudgeField> itrAliases = msgAliases.iterator();
   while (itrRequirements.hasNext() && itrAliases.hasNext()) {
     final FudgeField requirement = itrRequirements.next();
     final FudgeField alias = itrAliases.next();
     final ValueSpecification spec =
         deserializer.fieldValueToObject(ValueSpecification.class, requirement);
     if (alias.getValue() == IndicatorType.INSTANCE) {
       result.put(spec, Collections.singleton(spec));
     } else {
       final FudgeMsg msgAlias = (FudgeMsg) alias.getValue();
       final String clazz = msgAlias.getString(0);
       if ("list".equals(clazz)) {
         final Collection<ValueSpecification> aliases =
             new ArrayList<ValueSpecification>(msgAlias.getNumFields() - 1);
         for (FudgeField aliasField : msgAlias) {
           if (aliasField.getValue() == IndicatorType.INSTANCE) {
             aliases.add(spec);
           } else if (aliasField.getValue() instanceof FudgeMsg) {
             aliases.add(deserializer.fieldValueToObject(ValueSpecification.class, aliasField));
           }
         }
         result.put(spec, aliases);
       } else {
         result.put(
             spec,
             Collections.singleton(
                 deserializer.fieldValueToObject(ValueSpecification.class, alias)));
       }
     }
   }
   return result;
 }
 protected Set<ComputationTargetSpecification> decodeComputationTargets(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg submsg = msg.getMessage(COMPUTATION_TARGETS_FIELD);
   if (submsg == null) {
     return Collections.emptySet();
   }
   final Set<ComputationTargetSpecification> result =
       Sets.newHashSetWithExpectedSize(submsg.getNumFields());
   for (final FudgeField field : submsg) {
     result.add(
         deserializer
             .fieldValueToObject(ComputationTargetReference.class, field)
             .getSpecification());
   }
   return result;
 }
  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);
  }
 @SuppressWarnings("unchecked")
 protected Map<ValueSpecification, Set<ValueRequirement>> decodeTerminalOutputSpecifications(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   final FudgeMsg submsg = msg.getMessage(TERMINAL_OUTPUT_SPECIFICATIONS_FIELD);
   if (submsg == null) {
     return Collections.emptyMap();
   }
   final Map<ValueSpecification, Set<ValueRequirement>> result =
       Maps.newHashMapWithExpectedSize(submsg.getNumFields() / 2);
   LinkedList<Object> overflow = null;
   ValueSpecification key = null;
   Set<ValueRequirement> value = null;
   for (final FudgeField field : submsg) {
     if (MAP_KEY.equals(field.getOrdinal())) {
       final ValueSpecification fieldValue =
           deserializer.fieldValueToObject(ValueSpecification.class, field);
       if (key == null) {
         if (value == null) {
           key = fieldValue;
         } else {
           result.put(fieldValue, value);
           if (overflow != null) {
             value = overflow.isEmpty() ? null : (Set<ValueRequirement>) overflow.removeFirst();
           } else {
             value = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     } else if (MAP_VALUE.equals(field.getOrdinal())) {
       final FudgeMsg submsg2 = (FudgeMsg) field.getValue();
       final Set<ValueRequirement> fieldValue =
           Sets.newHashSetWithExpectedSize(submsg2.getNumFields());
       for (final FudgeField field2 : submsg2) {
         fieldValue.add(deserializer.fieldValueToObject(ValueRequirement.class, field2));
       }
       if (value == null) {
         if (key == null) {
           value = fieldValue;
         } else {
           result.put(key, fieldValue);
           if (overflow != null) {
             key = overflow.isEmpty() ? null : (ValueSpecification) overflow.removeFirst();
           } else {
             key = null;
           }
         }
       } else {
         if (overflow == null) {
           overflow = new LinkedList<Object>();
         }
         overflow.add(fieldValue);
       }
     }
   }
   return result;
 }