public void TestRoundTrip()
        {
            NetworkBinaryWriter w = Writer();

            StreamWireFormatting.WriteBool(w, true);
            StreamWireFormatting.WriteInt32(w, 1234);
            StreamWireFormatting.WriteInt16(w, 1234);
            StreamWireFormatting.WriteByte(w, 123);
            StreamWireFormatting.WriteChar(w, 'x');
            StreamWireFormatting.WriteInt64(w, 1234);
            StreamWireFormatting.WriteSingle(w, 1.234f);
            StreamWireFormatting.WriteDouble(w, 1.234);
            StreamWireFormatting.WriteBytes(w, new byte[] { 1, 2, 3, 4 });
            StreamWireFormatting.WriteString(w, "hello");
            StreamWireFormatting.WriteObject(w, "world");
            NetworkBinaryReader r = Reader(Contents(w));

            Assert.AreEqual(true, StreamWireFormatting.ReadBool(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt32(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt16(r));
            Assert.AreEqual(123, StreamWireFormatting.ReadByte(r));
            Assert.AreEqual('x', StreamWireFormatting.ReadChar(r));
            Assert.AreEqual(1234, StreamWireFormatting.ReadInt64(r));
            Assert.AreEqual(1.234f, StreamWireFormatting.ReadSingle(r));
            Assert.AreEqual(1.234, StreamWireFormatting.ReadDouble(r));
            Assert.AreEqual(new byte[] { 1, 2, 3, 4 }, StreamWireFormatting.ReadBytes(r));
            Assert.AreEqual("hello", StreamWireFormatting.ReadString(r));
            Assert.AreEqual("world", StreamWireFormatting.ReadObject(r));
        }
示例#2
0
        /// <summary>
        /// 推送消息
        /// </summary>
        /// <param name="exchange"></param>
        /// <param name="routingKey"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool BasicPublish(string exchange, string routingKey, string context)
        {
            try
            {
                NetworkBinaryWriter networkBinaryReader = new NetworkBinaryWriter(new MemoryStream());
                StreamWireFormatting.WriteString(networkBinaryReader, "nihao");

                //消息属性
                //  var propertity=  channel.CreateBasicProperties();
                //消息推送
                channel.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(context));
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public void TestSingleDecoding2()
 {
     Assert.AreEqual(1.234f.ToString(),
                     StreamWireFormatting.ReadString(Reader
                                                         (new byte[] { 8, 63, 157, 243, 182 })));
 }
示例#4
0
 /// <summary>
 /// Writes a section of a byte array into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteBytes(byte[] source, int offset, int count)
 {
     StreamWireFormatting.WriteBytes(Writer, source, offset, count);
     return(this);
 }
示例#5
0
 /// <summary>
 /// Writes a <see cref="byte"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteByte(byte value)
 {
     StreamWireFormatting.WriteByte(Writer, value);
     return(this);
 }
示例#6
0
 /// <summary>
 /// Writes a <see cref="bool"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteBool(bool value)
 {
     StreamWireFormatting.WriteBool(Writer, value);
     return(this);
 }
示例#7
0
 /// <summary>
 /// Writes a <see cref="float"/>string value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteString(string value)
 {
     StreamWireFormatting.WriteString(Writer, value);
     return(this);
 }
示例#8
0
 /// <summary>
 /// Writes a <see cref="float"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteSingle(float value)
 {
     StreamWireFormatting.WriteSingle(Writer, value);
     return(this);
 }
示例#9
0
 /// <summary>
 /// Writes an <see cref="object"/> value into the message body being assembled.
 /// </summary>
 /// <remarks>
 /// The only permitted types are bool, int, short, byte, char,
 /// long, float, double, byte[] and string.
 /// </remarks>
 public IStreamMessageBuilder WriteObject(object value)
 {
     StreamWireFormatting.WriteObject(Writer, value);
     return(this);
 }
示例#10
0
 /// <summary>
 /// Writes a <see cref="long"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteInt64(long value)
 {
     StreamWireFormatting.WriteInt64(Writer, value);
     return(this);
 }
示例#11
0
 /// <summary>
 /// Writes a <see cref="short"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteInt16(short value)
 {
     StreamWireFormatting.WriteInt16(Writer, value);
     return(this);
 }
示例#12
0
 /// <summary>
 /// Writes a <see cref="char"/> value into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteChar(char value)
 {
     StreamWireFormatting.WriteChar(Writer, value);
     return(this);
 }
示例#13
0
 /// <summary>
 /// Writes a <see cref="byte"/> array into the message body being assembled.
 /// </summary>
 public IStreamMessageBuilder WriteBytes(byte[] source)
 {
     StreamWireFormatting.WriteBytes(Writer, source);
     return(this);
 }