public void Call_WithHeader() { var header = new Tuple <string, object>("transaction", 0); byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { new HessianOutputV1(writer).WriteCall("debug", new object[] { 197067 }, new[] { header }); actual = ms.ToArray(); } var expected = new HessianDataBuilder() // call .WriteChar('c') // version (major version 1, minor 0) .WriteBytes(1, 0) // header(s) .WriteChar('H') .WriteBytes(0, 0x0B).WriteUtf8("transaction") .WriteChar('I').WriteBytes(0, 0, 0, 0) // method name .WriteChar('m').WriteBytes(0, 0x05).WriteUtf8("debug") // arg1 .WriteChar('I').WriteBytes(0, 0x03, 0x01, 0xCB) // call end .WriteChar('z') .ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Call() { byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { new HessianOutputV1(writer).WriteCall("add2", new object[] { 2, 3 }); actual = ms.ToArray(); } var expected = new HessianDataBuilder() // call .WriteChar('c') // version (major version 1, minor 0) .WriteBytes(1, 0) // method name .WriteChar('m').WriteBytes(0, 0x04).WriteUtf8("add2") // arg1 .WriteChar('I').WriteBytes(0, 0, 0, 0x02) // arg2 .WriteChar('I').WriteBytes(0, 0, 0, 0x03) // call end .WriteChar('z') .ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void List_Compact_Fixed_UsingTypeRef() { var first = new int[] { 0, 1 }; var second = new int[] { 2, 3, 4 }; var expected = new HessianDataBuilder() // first list .WriteBytes(0x72) // list tag .WriteBytes(0x04).WriteUtf8("[int") // type .WriteBytes(0x90) // int 0 .WriteBytes(0x91) // int 1 // second list .WriteBytes(0x73) // list tag .WriteBytes(0x90) // type ref 0 (above [int) .WriteBytes(0x92) // int 2 .WriteBytes(0x93) // int 3 .WriteBytes(0x94) // int 4 .ToArray(); byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { var output = new HessianOutputV2(writer, TypeBindings.Java); output.WriteObject(first); output.WriteObject(second); actual = ms.ToArray(); } CollectionAssert.AreEqual(expected, actual); }
private static byte[] Serialize(object obj, TypeBindings bindings = null) { using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { new HessianOutputV1(writer, bindings ?? TypeBindings.Java).WriteObject(obj); return(ms.ToArray()); } }
/// <inheritdoc/> protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { return(Task.Run(() => { using (var writer = new HessianStreamWriter(stream, true)) { _outputFactory(writer).WriteCall(_methodName, _args); } })); }
public void Map_CompactEnum() { var first = Color.RED; var second = Color.GREEN; var third = Color.BLUE; var fourth = Color.GREEN; byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { var output = new HessianOutputV2(writer); output.WriteObject(first); output.WriteObject(second); output.WriteObject(third); output.WriteObject(fourth); actual = ms.ToArray(); } var expected = new HessianDataBuilder() .WriteChar('C') .WriteBytes(0x0d).WriteUtf8("example.Color") .WriteBytes(0x91) // one field .WriteBytes(0x04).WriteUtf8("name") .WriteBytes(0x60) // reference definition .WriteBytes(0x03).WriteUtf8("RED") .WriteBytes(0x60) .WriteBytes(0x05).WriteUtf8("GREEN") .WriteBytes(0x60) .WriteBytes(0x04).WriteUtf8("BLUE") .WriteChar('Q').WriteBytes(0x91) // GREEN .ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Call() { byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { new HessianOutputV2(writer).WriteCall("add2", new object[] { 2, 3 }); actual = ms.ToArray(); } var expected = new HessianDataBuilder() .WriteChar('H').WriteBytes(0x02, 0x00) // version .WriteChar('C') // call .WriteBytes(0x04).WriteUtf8("add2") // method .WriteBytes(0x92) // 2 arguments .WriteBytes(0x92) // arg1 .WriteBytes(0x93) // arg2 .ToArray(); CollectionAssert.AreEqual(expected, actual); }
public void Call_WithRef() { var bean = new Bean { foo = 13 }; byte[] actual; using (var ms = new MemoryStream()) using (var writer = new HessianStreamWriter(ms)) { new HessianOutputV1(writer).WriteCall("eq", new object[] { bean, bean }); actual = ms.ToArray(); } var expected = new HessianDataBuilder() // call .WriteChar('c') // version (major version 1, minor 0) .WriteBytes(1, 0) // method name .WriteChar('m').WriteBytes(0, 0x02).WriteUtf8("eq") // arg1 .WriteChar('M') .WriteChar('t').WriteBytes(0, 0x07).WriteUtf8("qa.Bean") // field foo .WriteChar('S').WriteBytes(0, 0x03).WriteUtf8("foo") .WriteChar('I').WriteBytes(0, 0, 0, 0x0D) // end of map .WriteChar('z') // arg2: ref to arg 1 .WriteChar('R').WriteBytes(0, 0, 0, 0) // call end .WriteChar('z') .ToArray(); CollectionAssert.AreEqual(expected, actual); }
private HessianOutput CreateOutput(HessianStreamWriter writer) { return(_protocolVersion == ProtocolVersion.V1 ? (HessianOutput) new HessianOutputV1(writer, _typeBindings) : new HessianOutputV2(writer, _typeBindings)); }