public void BasicPack() { Assert.AreEqual(120, BStruct.Pack(120, 1)[0]); Assert.AreEqual(246, BStruct.Pack(-10, 1)[0]); Assert.AreEqual(226, BStruct.Pack(-30, 1)[0]); Assert.AreEqual(125, BStruct.Pack(32000, 2)[0]); Assert.AreEqual(131, BStruct.Pack(-32000, 2)[0]); Assert.AreEqual("\x00\x01\x86\xa0", Util.GetString(BStruct.Pack(100000, 4))); Assert.AreEqual("\xff\xfey`", Util.GetString(BStruct.Pack(-100000, 4))); }
public void BasicPack() { Assert.AreEqual(120, (int)BStruct.Pack(120, 1)[0]); Assert.AreEqual(246, (int)BStruct.Pack(-10, 1)[0]); Assert.AreEqual(226, (int)BStruct.Pack(-30, 1)[0]); Assert.AreEqual(125, (int)BStruct.Pack(32000, 2)[0]); Assert.AreEqual(131, (int)BStruct.Pack(-32000, 2)[0]); Assert.AreEqual("\x00\x01\x86\xa0", BStruct.Pack(100000, 4)); Assert.AreEqual("\xff\xfey`", BStruct.Pack(-100000, 4)); }
public void BasicUnpack() { //Assert.AreEqual(246, BStruct.ToBytes(-10)[0]); Assert.AreEqual(120, BStruct.Unpack(BStruct.Pack(120, 1), 1)); byte[] a = BStruct.Pack(-50, 1); Assert.AreEqual(206, a[0]); Assert.AreEqual(-50, BStruct.Unpack(a, 1)); Assert.AreEqual(32000, BStruct.Unpack(BStruct.Pack(32000, 2), 2)); }
public void BasicUnpack() { //Assert.AreEqual(246, BStruct.ToBytes(-10)[0]); Assert.AreEqual((sbyte)120, BStruct.Unpack(BStruct.Pack(120, 1), 1)); var a = BStruct.Pack(-50, 1); Assert.AreEqual(206, a[0]); Assert.AreEqual((sbyte)-50, BStruct.Unpack(a, 1)); Assert.AreEqual((short)32000, BStruct.Unpack(BStruct.Pack(32000, 2), 2)); }
public void Int4() { byte[] se = BStruct.Pack(1009025546, 4); Assert.AreEqual(60, se[0]); Assert.AreEqual(36, se[1]); Assert.AreEqual(130, se[2]); Assert.AreEqual(10, se[3]); int a = BStruct.ToInt32(new byte[] { 0, 0, 195, 80 }, 0); Assert.AreEqual(50000, a); a = BStruct.ToInt32(new byte[] { 255, 255, 60, 176 }, 0); Assert.AreEqual(-50000, a); }