public void AllOrdinalsCodecWithTaxonomy() { FudgeContext context = new FudgeContext(); FudgeMsg inputMsg = context.NewMessage(); inputMsg.Add(ORDINALS[0], "value1"); inputMsg.Add(ORDINALS[1], "value2"); inputMsg.Add(ORDINALS[2], "value3"); inputMsg.Add(ORDINALS[3], "value4"); var resolverMap = new Dictionary <int, IFudgeTaxonomy>(); resolverMap.Add(45, new MapFudgeTaxonomy(ORDINALS, NAMES)); context.TaxonomyResolver = new ImmutableMapTaxonomyResolver(resolverMap); FudgeMsg outputMsg = CycleMessage(inputMsg, context, (short)45); Assert.Equal("value1", outputMsg.GetString(NAMES[0])); Assert.Equal("value1", outputMsg.GetString(ORDINALS[0])); Assert.Equal("value2", outputMsg.GetString(NAMES[1])); Assert.Equal("value2", outputMsg.GetString(ORDINALS[1])); Assert.Equal("value3", outputMsg.GetString(NAMES[2])); Assert.Equal("value3", outputMsg.GetString(ORDINALS[2])); Assert.Equal("value4", outputMsg.GetString(NAMES[3])); Assert.Equal("value4", outputMsg.GetString(ORDINALS[3])); }
/// <inheritdoc/> public void StartSubMessage(string name, int? ordinal) { msgStack.Push(current); FudgeMsg newMsg = context.NewMessage(); current.Add(name, ordinal, newMsg); current = newMsg; }
public void GetAllNames() { var msg = new FudgeMsg(); msg.Add("foo", 3); msg.Add("bar", 17); msg.Add("foo", 2); // Deliberately do a duplicate var names = msg.GetAllFieldNames(); Assert.Equal(2, names.Count); Assert.Contains("foo", names); Assert.Contains("bar", names); }
public void VariableWidthColumnSizes() { FudgeMsg inputMsg = new FudgeMsg(); inputMsg.Add("100", new byte[100]); inputMsg.Add("1000", new byte[1000]); inputMsg.Add("10000", new byte[100000]); FudgeMsg outputMsg = CycleMessage(inputMsg); Assert.NotNull(outputMsg); FudgeUtils.AssertAllFieldsMatch(inputMsg, outputMsg); }
protected override void SerializeImpl(ValueProperties obj, IAppendingFudgeFieldContainer msg, IFudgeSerializer serializer) { var finite = obj as FiniteValueProperties; if (finite != null) { finite.Serialize(msg, serializer); } else { if (obj is EmptyValueProperties) { return; } var withoutMessage = new FudgeMsg(serializer.Context); if (obj is NearlyInfiniteValueProperties) { foreach (var without in ((NearlyInfiniteValueProperties)obj).Without) { withoutMessage.Add((string)null, without); } } msg.Add("without", withoutMessage); } }
public void LookupByNameMultipleValues() { FudgeMsg msg = StandardFudgeMessages.CreateMessageAllNames(fudgeContext); IFudgeField field = null; IList <IFudgeField> fields = null; // Now add a second by name. msg.Add("boolean", true); field = msg.GetByName("boolean"); Assert.NotNull(field); Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type); Assert.Equal(true, field.Value); Assert.Equal("boolean", field.Name); Assert.Null(field.Ordinal); fields = msg.GetAllByName("boolean"); Assert.NotNull(fields); Assert.Equal(2, fields.Count); field = fields[0]; Assert.NotNull(field); Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type); Assert.Equal(true, field.Value); Assert.Equal("boolean", field.Name); Assert.Null(field.Ordinal); field = fields[1]; Assert.NotNull(field); Assert.Equal(PrimitiveFieldTypes.BooleanType, field.Type); Assert.Equal(true, field.Value); Assert.Equal("boolean", field.Name); Assert.Null(field.Ordinal); }
public void LongInLongOut() { FudgeMsg msg = new FudgeMsg(); msg.Add("test", (long)5); Assert.Equal((long)5, msg.GetLong("test")); }
public void Serialize(IAppendingFudgeFieldContainer a, IFudgeSerializer s) { var context = s.Context; var withMessage = new FudgeMsg(context); var v = new string[1]; foreach (var property in PropertyValues) { if (property.Value == null) { var optMessage = new FudgeMsg(context) { { (string)null, IndicatorType.Instance } }; withMessage.Add(property.Key, optMessage); } else if (0 == property.Value.Count) { withMessage.Add(property.Key, IndicatorType.Instance); } else if (property.Value.Count == 1) { property.Value.CopyTo(v, 0); withMessage.Add(property.Key, v[0]); } else { var manyMesssage = new FudgeMsg(context); foreach (var val in property.Value) { manyMesssage.Add(property.Key, val); } withMessage.Add(property.Key, manyMesssage); } } if (_optional != null) { foreach (var optional in _optional) { withMessage.Add(optional, new FudgeMsg(context, new Field("optional", IndicatorType.Instance))); } } a.Add("with", withMessage); }
internal static FudgeMsg CreateMessageAllByteArrayLengths(FudgeContext context) { FudgeMsg msg = context.NewMessage(); msg.Add("byte[4]", new byte[4]); msg.Add("byte[8]", new byte[8]); msg.Add("byte[16]", new byte[16]); msg.Add("byte[20]", new byte[20]); msg.Add("byte[32]", new byte[32]); msg.Add("byte[64]", new byte[64]); msg.Add("byte[128]", new byte[128]); msg.Add("byte[256]", new byte[256]); msg.Add("byte[512]", new byte[512]); msg.Add("byte[28]", new byte[28]); return(msg); }
public void AddingFieldContainerCopiesFields() { var msg = new FudgeMsg(); // Add a normal sub-message (shouldn't copy) IFudgeFieldContainer sub1 = new FudgeMsg(new Field("age", 37)); msg.Add("sub1", sub1); Assert.Same(sub1, msg.GetValue("sub1")); // Add a sub-message that isn't a FudgeMsg (should copy) IFudgeFieldContainer sub2 = (IFudgeFieldContainer)new Field("dummy", new Field("colour", "blue")).Value; Assert.IsNotType<FudgeMsg>(sub2); // Just making sure msg.Add("sub2", sub2); Assert.NotSame(sub2, msg.GetValue("sub2")); Assert.IsType<FudgeMsg>(msg.GetValue("sub2")); Assert.Equal("blue", msg.GetMessage("sub2").GetString("colour")); }
/// <summary> /// Will output a <see cref="FudgeMsg"/> to <see cref="Console.Out"/> so that you can visually /// examine it. /// </summary> public void OutputToStdoutAllOrdinals() { Console.Out.WriteLine("FudgeMsgFormatterTest.OutputToStdoutAllOrdinals()"); FudgeMsg msg = StandardFudgeMessages.CreateMessageAllOrdinals(fudgeContext); msg.Add("Sub Message", (short)9999, StandardFudgeMessages.CreateMessageAllOrdinals(fudgeContext)); new FudgeMsgFormatter(Console.Out).Format(msg); }
public void CheckSecondaryTypes() { var msg = new FudgeMsg(context); var dt = new DateTime(1987, 1, 13, 8, 6, 5); var dto = new DateTimeOffset(1822, 7, 20, 13, 2, 15, new TimeSpan(-2, 0, 0)); msg.Add("dt", dt); msg.Add("dto", dto); Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dt").Type); Assert.IsType<FudgeDateTime>(msg.GetByName("dt").Value); Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dto").Type); Assert.IsType<FudgeDateTime>(msg.GetByName("dto").Value); Assert.Equal(dt, msg.GetValue<DateTime>("dt")); Assert.Equal(dto, msg.GetValue<DateTime>("dto")); }
public void Minimization() { FudgeMsg msg = new FudgeMsg(); msg.Add("int?", 17); Assert.Same(PrimitiveFieldTypes.SByteType, msg.GetByName("int?").Type); }
public void CheckSecondaryTypes() { var msg = new FudgeMsg(context); var dt = new DateTime(1987, 1, 13, 8, 6, 5); var dto = new DateTimeOffset(1822, 7, 20, 13, 2, 15, new TimeSpan(-2, 0, 0)); msg.Add("dt", dt); msg.Add("dto", dto); Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dt").Type); Assert.IsType <FudgeDateTime>(msg.GetByName("dt").Value); Assert.Same(DateTimeFieldType.Instance, msg.GetByName("dto").Type); Assert.IsType <FudgeDateTime>(msg.GetByName("dto").Value); Assert.Equal(dt, msg.GetValue <DateTime>("dt")); Assert.Equal(dto, msg.GetValue <DateTime>("dto")); }
public void Unknown() { FudgeMsg inputMsg = new FudgeMsg(); inputMsg.Add("unknown", new UnknownFudgeFieldValue(new byte[10], new FudgeTypeDictionary().GetUnknownType(200))); FudgeMsg outputMsg = CycleMessage(inputMsg); FudgeUtils.AssertAllFieldsMatch(inputMsg, outputMsg); }
public void AddingFieldContainerCopiesFields() { var msg = new FudgeMsg(); // Add a normal sub-message (shouldn't copy) IFudgeFieldContainer sub1 = new FudgeMsg(new Field("age", 37)); msg.Add("sub1", sub1); Assert.Same(sub1, msg.GetValue("sub1")); // Add a sub-message that isn't a FudgeMsg (should copy) IFudgeFieldContainer sub2 = (IFudgeFieldContainer) new Field("dummy", new Field("colour", "blue")).Value; Assert.IsNotType <FudgeMsg>(sub2); // Just making sure msg.Add("sub2", sub2); Assert.NotSame(sub2, msg.GetValue("sub2")); Assert.IsType <FudgeMsg>(msg.GetValue("sub2")); Assert.Equal("blue", msg.GetMessage("sub2").GetString("colour")); }
public void ToFudgeMsg(IAppendingFudgeFieldContainer calcConfigMsg, IFudgeSerializer s) { var context = s.Context; var fudgeSerializer = new FudgeSerializer(context); calcConfigMsg.Add("name", Name); foreach (var securityTypeRequirements in PortfolioRequirementsBySecurityType) { FudgeMsg securityTypeRequirementsMsg = new FudgeMsg(context); securityTypeRequirementsMsg.Add("securityType", securityTypeRequirements.Key); foreach (var requirement in securityTypeRequirements.Value) { var newMessage = context.NewMessage(); newMessage.Add("requiredOutput", requirement.Item1); newMessage.Add("constraints", fudgeSerializer.SerializeToMsg(requirement.Item2)); securityTypeRequirementsMsg.Add("portfolioRequirement", newMessage); } calcConfigMsg.Add("portfolioRequirementsBySecurityType", securityTypeRequirementsMsg); } foreach (var specificRequirement in SpecificRequirements) { var sReqMsg = fudgeSerializer.SerializeToMsg(specificRequirement); calcConfigMsg.Add("specificRequirement", sReqMsg); } var defaultPropsMessage = fudgeSerializer.SerializeToMsg(DefaultProperties); calcConfigMsg.Add("defaultProperties", defaultPropsMessage); var deltaDefnMessage = fudgeSerializer.SerializeToMsg(_deltaDefinition); calcConfigMsg.Add("deltaDefinition", deltaDefnMessage); if (ResolutionRuleTransform != null) { var transformMessage = fudgeSerializer.SerializeToMsg(ResolutionRuleTransform); calcConfigMsg.Add("resolutionRuleTransform", transformMessage); } }
internal static FudgeMsg CreateLargeMessage(FudgeContext context) { FudgeMsg msg = context.NewMessage(); for (int i = short.MinValue - 1; i <= short.MaxValue + 1; i++) { msg.Add(string.Format("field{0}", i), "FRN-91"); } return(msg); }
public void Minimsation() { var msg = new FudgeMsg(context); var dt = new DateTime(1990, 2, 1); var fdt = new FudgeDateTime(1990, 2, 1, 0, 0, 0, 0, FudgeDateTimePrecision.Day); msg.Add("dt", dt); msg.Add("fdt", fdt); Assert.Same(DateFieldType.Instance, msg.GetByName("dt").Type); Assert.IsType<FudgeDate>(msg.GetByName("dt").Value); Assert.Same(DateFieldType.Instance, msg.GetByName("fdt").Type); Assert.IsType<FudgeDate>(msg.GetByName("fdt").Value); Assert.Equal(dt, msg.GetValue<DateTime>("dt")); Assert.Equal(fdt, msg.GetValue<FudgeDateTime>("fdt")); // Error cases FudgeFieldType type = null; Assert.Equal(null, DateTimeFieldType.Instance.Minimize(null, ref type)); Assert.Throws<ArgumentException>(() => DateTimeFieldType.Instance.Minimize("fred", ref type)); }
public void Minimsation() { var msg = new FudgeMsg(context); var dt = new DateTime(1990, 2, 1); var fdt = new FudgeDateTime(1990, 2, 1, 0, 0, 0, 0, FudgeDateTimePrecision.Day); msg.Add("dt", dt); msg.Add("fdt", fdt); Assert.Same(DateFieldType.Instance, msg.GetByName("dt").Type); Assert.IsType <FudgeDate>(msg.GetByName("dt").Value); Assert.Same(DateFieldType.Instance, msg.GetByName("fdt").Type); Assert.IsType <FudgeDate>(msg.GetByName("fdt").Value); Assert.Equal(dt, msg.GetValue <DateTime>("dt")); Assert.Equal(fdt, msg.GetValue <FudgeDateTime>("fdt")); // Error cases FudgeFieldType type = null; Assert.Equal(null, DateTimeFieldType.Instance.Minimize(null, ref type)); Assert.Throws <ArgumentException>(() => DateTimeFieldType.Instance.Minimize("fred", ref type)); }
public void ToFudgeMsg(IAppendingFudgeFieldContainer a, IFudgeSerializer s) { s.WriteTypeHeader(a, GetType()); var fudgeMsg = new FudgeMsg(s.Context); foreach (var viewCycleExecutionOptionse in _executionSequence) { FudgeMsg msg = ((OpenGammaFudgeContext)s.Context).GetSerializer().SerializeToMsg(viewCycleExecutionOptionse); fudgeMsg.Add(null, null, msg); } a.Add("sequence", fudgeMsg); }
protected override void SerializeImpl(ComputationCacheQuery obj, IAppendingFudgeFieldContainer msg, IFudgeSerializer s) { var fudgeContext = s.Context; msg.Add("calculationConfigurationName", obj.CalculationConfigurationName); var fudgeMsg = new FudgeMsg(fudgeContext); var s2 = ((OpenGammaFudgeContext)fudgeContext).GetSerializer(); foreach (var valueSpecification in obj.ValueSpecifications) { fudgeMsg.Add(null, null, s2.SerializeToMsg(valueSpecification)); } msg.Add("valueSpecifications", fudgeMsg); }
public static FudgeMsg ToFudgeMsg <TKey, TValue>(IFudgeSerializer s, IDictionary <TKey, TValue> dict, Func <TKey, object> keyMsgGen = null, Func <TValue, object> valueMsgGen = null) where TValue : class { var fudgeSerializer = new FudgeSerializer(s.Context); keyMsgGen = keyMsgGen ?? (k => fudgeSerializer.SerializeToMsg(k)); valueMsgGen = valueMsgGen ?? (v => fudgeSerializer.SerializeToMsg(v)); var valuesMessage = new FudgeMsg(s.Context); foreach (var value in dict) { valuesMessage.Add(1, keyMsgGen(value.Key)); if (value.Value == null) { valuesMessage.Add(2, IndicatorType.Instance); } else { valuesMessage.Add(2, valueMsgGen(value.Value)); } } return(valuesMessage); }
private static int FudgeCycle(bool useNames, bool useOrdinals) { MemoryStream outputStream = new MemoryStream(); var bw = new FudgeBinaryWriter(outputStream); SmallFinancialTick tick = new SmallFinancialTick(); FudgeMsg msg = new FudgeMsg(fudgeContext); if (useNames && useOrdinals) { msg.Add("ask", (short)1, tick.Ask); msg.Add("askVolume", (short)2, tick.AskVolume); msg.Add("bid", (short)3, tick.Bid); msg.Add("bidVolume", (short)4, tick.BidVolume); msg.Add("ts", (short)5, tick.Timestamp); } else if (useNames) { msg.Add("ask", tick.Ask); msg.Add("askVolume", tick.AskVolume); msg.Add("bid", tick.Bid); msg.Add("bidVolume", tick.BidVolume); msg.Add("ts", tick.Timestamp); } else if (useOrdinals) { msg.Add(1, tick.Ask); msg.Add(2, tick.AskVolume); msg.Add(3, tick.Bid); msg.Add(4, tick.BidVolume); msg.Add(5, tick.Timestamp); } fudgeContext.Serialize(msg, bw); byte[] data = outputStream.ToArray(); MemoryStream inputstream = new MemoryStream(data); var br = new FudgeBinaryReader(inputstream); msg = fudgeContext.Deserialize(inputstream).Message; tick = new SmallFinancialTick(); if (useOrdinals) { tick.Ask = msg.GetDouble(1).Value; tick.AskVolume = msg.GetDouble(2).Value; tick.Bid = msg.GetDouble(3).Value; tick.BidVolume = msg.GetDouble(4).Value; tick.Timestamp = msg.GetLong(5).Value; } else if (useNames) { tick.Ask = msg.GetDouble("ask").Value; tick.AskVolume = msg.GetDouble("askVolume").Value; tick.Bid = msg.GetDouble("bid").Value; tick.BidVolume = msg.GetDouble("bidVolume").Value; tick.Timestamp = msg.GetLong("ts").Value; } else { throw new InvalidOperationException("Names or ordinals, pick at least one."); } return(data.Length); }
/** * @param reader * @param msg */ protected void ProcessFields(IFudgeStreamReader reader, FudgeMsg msg) { while (reader.HasNext) { FudgeStreamElement element = reader.MoveNext(); switch (element) { case FudgeStreamElement.SimpleField: msg.Add(reader.FieldName, reader.FieldOrdinal, reader.FieldType, reader.FieldValue); break; case FudgeStreamElement.SubmessageFieldStart: FudgeMsg subMsg = FudgeContext.NewMessage(); msg.Add(reader.FieldName, reader.FieldOrdinal, subMsg); ProcessFields(reader, subMsg); break; case FudgeStreamElement.SubmessageFieldEnd: case FudgeStreamElement.MessageEnd: return; } } }
public void HasField_FRN82() { var msg = new FudgeMsg(); msg.Add("foo", 3); msg.Add(17, "bar"); Assert.True(msg.HasField("foo")); Assert.False(msg.HasField("bar")); Assert.True(msg.HasField(17)); Assert.False(msg.HasField(3)); }
internal static FudgeMsg CreateMessageAllNames(FudgeContext context) { FudgeMsg msg = context.NewMessage(); msg.Add("boolean", true); msg.Add("Boolean", (object)false); msg.Add("byte", (sbyte)5); msg.Add("Byte", (object)((sbyte)5)); short shortValue = ((short)sbyte.MaxValue) + 5; msg.Add("short", shortValue); msg.Add("Short", (object)(shortValue)); int intValue = ((int)short.MaxValue) + 5; msg.Add("int", intValue); msg.Add("Integer", (object)(intValue)); long longValue = ((long)int.MaxValue) + 5; msg.Add("long", longValue); msg.Add("Long", (object)(longValue)); msg.Add("float", 0.5f); msg.Add("Float", (object)(0.5f)); msg.Add("double", 0.27362); msg.Add("Double", (object)(0.27362)); msg.Add("String", "Kirk Wylie"); msg.Add("float array", new float[24]); msg.Add("double array", new double[273]); msg.Add("short array", new short[32]); msg.Add("int array", new int[83]); msg.Add("long array", new long[837]); msg.Add("indicator", IndicatorType.Instance); return(msg); }
private static int FudgeCycle(bool useNames, bool useOrdinals) { MemoryStream outputStream = new MemoryStream(); var bw = new FudgeBinaryWriter(outputStream); SmallFinancialTick tick = new SmallFinancialTick(); FudgeMsg msg = new FudgeMsg(fudgeContext); if (useNames && useOrdinals) { msg.Add("ask", (short)1, tick.Ask); msg.Add("askVolume", (short)2, tick.AskVolume); msg.Add("bid", (short)3, tick.Bid); msg.Add("bidVolume", (short)4, tick.BidVolume); msg.Add("ts", (short)5, tick.Timestamp); } else if (useNames) { msg.Add("ask", tick.Ask); msg.Add("askVolume", tick.AskVolume); msg.Add("bid", tick.Bid); msg.Add("bidVolume", tick.BidVolume); msg.Add("ts", tick.Timestamp); } else if (useOrdinals) { msg.Add(1, tick.Ask); msg.Add(2, tick.AskVolume); msg.Add(3, tick.Bid); msg.Add(4, tick.BidVolume); msg.Add(5, tick.Timestamp); } fudgeContext.Serialize(msg, bw); byte[] data = outputStream.ToArray(); MemoryStream inputstream = new MemoryStream(data); var br = new FudgeBinaryReader(inputstream); msg = fudgeContext.Deserialize(inputstream).Message; tick = new SmallFinancialTick(); if (useOrdinals) { tick.Ask = msg.GetDouble(1).Value; tick.AskVolume = msg.GetDouble(2).Value; tick.Bid = msg.GetDouble(3).Value; tick.BidVolume = msg.GetDouble(4).Value; tick.Timestamp = msg.GetLong(5).Value; } else if (useNames) { tick.Ask = msg.GetDouble("ask").Value; tick.AskVolume = msg.GetDouble("askVolume").Value; tick.Bid = msg.GetDouble("bid").Value; tick.BidVolume = msg.GetDouble("bidVolume").Value; tick.Timestamp = msg.GetLong("ts").Value; } else { throw new InvalidOperationException("Names or ordinals, pick at least one."); } return data.Length; }
internal static FudgeMsg CreateMessageAllOrdinals(FudgeContext context) { FudgeMsg msg = context.NewMessage(); msg.Add(1, true); msg.Add(2, (object)(false)); msg.Add(3, (sbyte)5); msg.Add(4, (object)((sbyte)5)); short shortValue = ((short)sbyte.MaxValue) + 5; msg.Add(5, shortValue); msg.Add(6, (object)(shortValue)); int intValue = ((int)short.MaxValue) + 5; msg.Add(7, intValue); msg.Add(8, (object)(intValue)); long longValue = ((long)int.MaxValue) + 5; msg.Add(9, longValue); msg.Add(10, (object)(longValue)); msg.Add(11, 0.5f); msg.Add(12, (object)(0.5f)); msg.Add(13, 0.27362); msg.Add(14, (object)(0.27362)); msg.Add(15, "Kirk Wylie"); msg.Add(16, new float[24]); msg.Add(17, new double[273]); return(msg); }