public void Check(MethodArgumentWriter w, byte[] expected)
 {
     byte[] actual = Contents(w);
     try
     {
         Assert.AreEqual(expected, actual);
     }
     catch
     {
         Console.WriteLine();
         Console.WriteLine("EXPECTED ==================================================");
         DebugUtil.Dump(expected);
         Console.WriteLine("ACTUAL ====================================================");
         DebugUtil.Dump(actual);
         Console.WriteLine("===========================================================");
         throw;
     }
 }
Ejemplo n.º 2
0
        public void Transmit(int channelNumber, Connection connection)
        {
            var frame = new Frame(Constants.FrameMethod, channelNumber);
            NetworkBinaryWriter writer = frame.GetWriter();

            writer.Write((ushort)Method.ProtocolClassId);
            writer.Write((ushort)Method.ProtocolMethodId);
            var argWriter = new MethodArgumentWriter(writer);

            Method.WriteArgumentsTo(argWriter);
            argWriter.Flush();
            connection.WriteFrame(frame);

            if (Method.HasContent)
            {
                byte[] body = Body;

                frame  = new Frame(Constants.FrameHeader, channelNumber);
                writer = frame.GetWriter();
                writer.Write((ushort)Header.ProtocolClassId);
                Header.WriteTo(writer, (ulong)body.Length);
                connection.WriteFrame(frame);

                var frameMax       = (int)Math.Min(int.MaxValue, connection.FrameMax);
                int bodyPayloadMax = (frameMax == 0)
                    ? body.Length
                    : frameMax - EmptyFrameSize;
                for (int offset = 0; offset < body.Length; offset += bodyPayloadMax)
                {
                    int remaining = body.Length - offset;

                    frame  = new Frame(Constants.FrameBody, channelNumber);
                    writer = frame.GetWriter();
                    writer.Write(body, offset,
                                 (remaining < bodyPayloadMax) ? remaining : bodyPayloadMax);
                    connection.WriteFrame(frame);
                }
            }
        }
 public byte[] Contents(MethodArgumentWriter w)
 {
     return ((MemoryStream)w.BaseWriter.BaseStream).ToArray();
 }
 public void SetUp()
 {
     m_w = Writer();
 }
Ejemplo n.º 5
0
 public abstract void WriteArgumentsTo(MethodArgumentWriter writer);
Ejemplo n.º 6
0
 public abstract void WriteArgumentsTo(MethodArgumentWriter writer);
Ejemplo n.º 7
0
        public void Transmit(int channelNumber, ConnectionBase connection)
        {
            Frame frame = new Frame(CommonFraming.Constants.FrameMethod, channelNumber);
            NetworkBinaryWriter writer = frame.GetWriter();
            writer.Write((ushort) m_method.ProtocolClassId);
            writer.Write((ushort) m_method.ProtocolMethodId);
            MethodArgumentWriter argWriter = new MethodArgumentWriter(writer);
            m_method.WriteArgumentsTo(argWriter);
            argWriter.Flush();
            connection.WriteFrame(frame);

            if (m_method.HasContent) {
                byte[] body = Body;

                frame = new Frame(CommonFraming.Constants.FrameHeader, channelNumber);
                writer = frame.GetWriter();
                writer.Write((ushort) m_header.ProtocolClassId);
                m_header.WriteTo(writer, (ulong) body.Length);
                connection.WriteFrame(frame);

                int frameMax = (int) Math.Min(int.MaxValue, connection.FrameMax);
                int bodyPayloadMax = (frameMax == 0)
                    ? body.Length
                    : frameMax - EmptyFrameSize;
                for (int offset = 0; offset < body.Length; offset += bodyPayloadMax) {
                    int remaining = body.Length - offset;

                    frame = new Frame(CommonFraming.Constants.FrameBody, channelNumber);
                    writer = frame.GetWriter();
                    writer.Write(body, offset,
                                 (remaining < bodyPayloadMax) ? remaining : bodyPayloadMax);
                    connection.WriteFrame(frame);
                }
            }
        }
Ejemplo n.º 8
0
 public void TransmitAsSingleFrame(int channelNumber, Connection connection)
 {
     var frame = new Frame(Constants.FrameMethod, channelNumber);
     NetworkBinaryWriter writer = frame.GetWriter();
     writer.Write((ushort)Method.ProtocolClassId);
     writer.Write((ushort)Method.ProtocolMethodId);
     var argWriter = new MethodArgumentWriter(writer);
     Method.WriteArgumentsTo(argWriter);
     argWriter.Flush();
     connection.WriteFrame(frame);
 }