/// <summary> /// Encodes a provided message into a byte array. /// </summary> /// <param name="message">The message to be encoded.</param> /// <returns>The encoded message as byte array.</returns> public static byte[] EncodeMessage(Message message) { var encoder = new Encoder(null); AlternativeCompositeByteBuf buf = AlternativeCompositeByteBuf.CompBuffer(); encoder.Write(buf, message, null); return(InteropUtil.ExtractBytes(buf)); }
public void TestEncodeByte() { var buffer = AlternativeCompositeByteBuf.CompBuffer(); // Java byte is signed for (int i = sbyte.MinValue; i <= sbyte.MaxValue; i++) // -128 ... 127 { buffer.WriteByte((sbyte)i); } var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
public void TestEncodeBytes() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); // Java byte is signed sbyte[] byteArray = new sbyte[256]; for (int i = 0, b = sbyte.MinValue; b <= sbyte.MaxValue; i++, b++) // -128 ... 127 { byteArray[i] = (sbyte)b; } buffer.WriteBytes(byteArray); var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
public void TestEncodeInt() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); buffer.WriteInt(int.MinValue); //-2147483648 buffer.WriteInt(-256); buffer.WriteInt(-255); buffer.WriteInt(-128); buffer.WriteInt(-127); buffer.WriteInt(-1); buffer.WriteInt(0); buffer.WriteInt(1); buffer.WriteInt(127); buffer.WriteInt(128); buffer.WriteInt(255); buffer.WriteInt(256); buffer.WriteInt(int.MaxValue); // 2147483647 var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
public void TestEncodeLong() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); buffer.WriteLong(long.MinValue); //-923372036854775808 buffer.WriteLong(-256); buffer.WriteLong(-255); buffer.WriteLong(-128); buffer.WriteLong(-127); buffer.WriteLong(-1); buffer.WriteLong(0); buffer.WriteLong(1); buffer.WriteLong(127); buffer.WriteLong(128); buffer.WriteLong(255); buffer.WriteLong(256); buffer.WriteLong(long.MaxValue); // 923372036854775807 var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }