public void TestNewMessage() { IsoMessage m = mfact.NewMessage(0x200); m.SetValue(2, "Variable length text", IsoType.LLLLVAR, 0); m.SetValue(3, "FFFF", IsoType.LLLLBIN, 0); Assert.Equal("020060000000000000000020Variable length text0004FFFF", m.DebugString()); m.Binary = (true); m.SetValue(2, "XX", IsoType.LLLLVAR, 0); m.SetValue(3, new sbyte[] { unchecked ((sbyte)0xff) }, IsoType.LLLLBIN, 0); Assert.Equal(new sbyte[] { 2, 0, (sbyte)0x60, 0, 0, 0, 0, 0, 0, 0, 0, 2, (sbyte)'X', (sbyte)'X', 0, 1, unchecked ((sbyte)0xff) }, m.WriteData()); }
public void TestEmptyLllbin() { IsoMessage t = txtfact.NewMessage(0x100); IsoMessage b = binfact.NewMessage(0x100); t.SetValue(6, new sbyte[0], IsoType.LLLBIN, 0); b.SetValue(6, new sbyte[0], IsoType.LLLBIN, 0); CheckBin(t.WriteData(), b.WriteData(), 6); }
public void TestEmptyLlllvar() { IsoMessage t = txtfact.NewMessage(0x100); IsoMessage b = binfact.NewMessage(0x100); t.SetValue(4, "", IsoType.LLLLVAR, 0); b.SetValue(4, "", IsoType.LLLLVAR, 0); CheckString(t.WriteData(), b.WriteData(), 4); }
public void TestL4bin() { sbyte[] fieldData = new sbyte[1000]; mfact.UseBinaryMessages = true; IsoMessage m = mfact.NewMessage(0x100); m.SetValue(3, fieldData, IsoType.LLLLBIN, 0); fieldData = m.WriteData(); //2 for message header //8 bitmap //3 for field 2 (from template) //1002 for field 3 Assert.Equal(1015, fieldData.Length); m = mfact.ParseMessage(fieldData, 0); Assert.True(m.HasField(3)); fieldData = m.GetObjectValue(3) as sbyte[]; Assert.Equal(1000, fieldData.Length); }
private void TestFieldType(IsoType type, FieldParseInfo fieldParser, int offset1, int offset2) { var bigintCodec = new BigIntBcdCodec(); var longCodec = new LongBcdCodec(); var mfact = new MessageFactory <IsoMessage>(); var tmpl = new IsoMessage { Binary = true, Type = 0x200 }; tmpl.SetValue(2, 1234567890L, longCodec, type, 0); tmpl.SetValue(3, b29, bigintCodec, type, 0); mfact.AddMessageTemplate(tmpl); mfact.SetCustomField(2, longCodec); mfact.SetCustomField(3, bigintCodec); var parser = new Dictionary <int, FieldParseInfo> { { 2, fieldParser }, { 3, fieldParser } }; mfact.SetParseMap(0x200, parser); mfact.UseBinaryMessages = true; //Test encoding tmpl = mfact.NewMessage(0x200); var buf = tmpl.WriteData(); var message = HexCodec.HexEncode(buf, 0, buf.Length); Console.WriteLine("MESSAGE: " + message); for (var i = 0; i < 5; i++) { var b = longData2[i]; Assert.Equal(b, buf[i + offset1]); } for (var i = 0; i < 15; i++) { Assert.Equal(bigintData1[i], buf[i + offset2]); } //Test parsing tmpl = mfact.ParseMessage(buf, 0); Assert.Equal(1234567890L, tmpl.GetObjectValue(2)); Assert.Equal(b29, tmpl.GetObjectValue(3)); }