public static void AssertAllFieldsMatch(FudgeMsg expectedMsg, FudgeMsg actualMsg) { var expectedIter = expectedMsg.GetAllFields().GetEnumerator(); var actualIter = actualMsg.GetAllFields().GetEnumerator(); while (expectedIter.MoveNext()) { Assert.True(actualIter.MoveNext()); IFudgeField expectedField = expectedIter.Current; IFudgeField actualField = actualIter.Current; Assert.Equal(expectedField.Name, actualField.Name); Assert.Equal(expectedField.Type, actualField.Type); Assert.Equal(expectedField.Ordinal, actualField.Ordinal); if (expectedField.Value.GetType().IsArray) { Assert.Equal(expectedField.Value.GetType(), actualField.Value.GetType()); Assert.Equal(expectedField.Value, actualField.Value); // XUnit will check all values in the arrays } else if (expectedField.Value is FudgeMsg) { Assert.True(actualField.Value is FudgeMsg); AssertAllFieldsMatch((FudgeMsg)expectedField.Value, (FudgeMsg)actualField.Value); } else if (expectedField.Value is UnknownFudgeFieldValue) { Assert.IsType <UnknownFudgeFieldValue>(actualField.Value); UnknownFudgeFieldValue expectedValue = (UnknownFudgeFieldValue)expectedField.Value; UnknownFudgeFieldValue actualValue = (UnknownFudgeFieldValue)actualField.Value; Assert.Equal(expectedField.Type.TypeId, actualField.Type.TypeId); Assert.Equal(expectedValue.Type.TypeId, actualField.Type.TypeId); Assert.Equal(expectedValue.Contents, actualValue.Contents); } else { Assert.Equal(expectedField.Value, actualField.Value); } } Assert.False(actualIter.MoveNext()); }
public static void AssertAllFieldsMatch(FudgeMsg expectedMsg, FudgeMsg actualMsg) { var expectedIter = expectedMsg.GetAllFields().GetEnumerator(); var actualIter = actualMsg.GetAllFields().GetEnumerator(); while (expectedIter.MoveNext()) { Assert.True(actualIter.MoveNext()); IFudgeField expectedField = expectedIter.Current; IFudgeField actualField = actualIter.Current; Assert.Equal(expectedField.Name, actualField.Name); Assert.Equal(expectedField.Type, actualField.Type); Assert.Equal(expectedField.Ordinal, actualField.Ordinal); if (expectedField.Value.GetType().IsArray) { Assert.Equal(expectedField.Value.GetType(), actualField.Value.GetType()); Assert.Equal(expectedField.Value, actualField.Value); // XUnit will check all values in the arrays } else if (expectedField.Value is FudgeMsg) { Assert.True(actualField.Value is FudgeMsg); AssertAllFieldsMatch((FudgeMsg)expectedField.Value, (FudgeMsg)actualField.Value); } else if (expectedField.Value is UnknownFudgeFieldValue) { Assert.IsType<UnknownFudgeFieldValue>(actualField.Value); UnknownFudgeFieldValue expectedValue = (UnknownFudgeFieldValue)expectedField.Value; UnknownFudgeFieldValue actualValue = (UnknownFudgeFieldValue)actualField.Value; Assert.Equal(expectedField.Type.TypeId, actualField.Type.TypeId); Assert.Equal(expectedValue.Type.TypeId, actualField.Type.TypeId); Assert.Equal(expectedValue.Contents, actualValue.Contents); } else { Assert.Equal(expectedField.Value, actualField.Value); } } Assert.False(actualIter.MoveNext()); }
public State(FudgeMsg msg) { Msg = msg; Fields = new Queue <IFudgeField>(msg.GetAllFields()); }
/// <summary> /// Encodes a <c>FudgeMsg</c> object to a <c>Stream</c> with an optional taxonomy reference. /// If a taxonomy is supplied it may be used to optimize the output by writing ordinals instead /// of field names. /// </summary> /// <param name="msg">the <c>FudgeMessage</c> to write</param> /// <param name="taxonomyId">the identifier of the taxonomy to use. Specify <c>null</c> for no taxonomy</param> /// <param name="bw">The <see cref="BinaryWriter"/> to serialise to</param> public void Serialize(FudgeMsg msg, short? taxonomyId, BinaryWriter bw) { try { var writer = new FudgeEncodedStreamWriter(this); writer.TaxonomyId = taxonomyId; writer.Reset(bw); writer.StartMessage(); writer.WriteFields(msg.GetAllFields()); writer.EndMessage(); } catch (IOException e) { throw new FudgeRuntimeException("Unable to write Fudge message to OutputStream", e); } }
public State(FudgeMsg msg) { Msg = msg; Fields = new Queue<IFudgeField>(msg.GetAllFields()); }