Exemplo n.º 1
0
        public void WriteString3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteString(s_normal);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(6));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o' }));

            e.Reset();
            e.WriteString(s_long);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(130));
            byte[] arr = new[] { e.Buffer[0], e.Buffer[1], e.Buffer[2], e.Buffer[3] };
            Assert.That(arr, Is.EquivalentTo(new byte[] { 0x80, 0x01, (byte)'*', (byte)'*' }));
            Assert.That(e.Buffer[128], Is.EqualTo((byte)'*'));
            Assert.That(e.Buffer[129], Is.EqualTo((byte)'x'));

            e.Reset();
            e.WriteString(s_big);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(65540));
            arr = new[] { e.Buffer[0], e.Buffer[1], e.Buffer[2], e.Buffer[3] };
            Assert.That(arr, Is.EquivalentTo(new byte[] { 0x81, 0x80, 0x04, (byte)'*' }));
            Assert.That(e.Buffer[65536], Is.EqualTo((byte)'*'));
            Assert.That(e.Buffer[65537], Is.EqualTo((byte)'x'));
            Assert.That(e.Buffer[65538], Is.EqualTo((byte)'x'));
            Assert.That(e.Buffer[65539], Is.EqualTo((byte)'x'));
        }
Exemplo n.º 2
0
        public void Reset()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteType(NtType.Unassigned);
            Assert.That(e.Error, Is.Not.Null);
            e.Reset();
            Assert.That(e.Error, Is.Null);

            e.Write8(0);
            Assert.That(e.Buffer.Length, Is.EqualTo(1));
            e.Reset();
            Assert.That(e.Buffer, Is.Empty);
        }
Exemplo n.º 3
0
        public void WriteValueError2()
        {
            WireEncoder e = new WireEncoder(0x0200);

            e.WriteValue(v_empty);
            Assert.That(e.Buffer.Length, Is.EqualTo(0));
            Assert.That(e.Error, Is.Not.Null);

            e.Reset();
            e.WriteValue(v_raw);
            Assert.That(e.Count, Is.EqualTo(0));
            Assert.That(e.Error, Is.Not.Null);

            e.Reset();
            e.WriteValue(v_rpc);
            Assert.That(e.Count, Is.EqualTo(0));
            Assert.That(e.Error, Is.Not.Null);
        }
Exemplo n.º 4
0
        public void WriteTypeError()
        {
            WireEncoder e = new WireEncoder(0x0200);

            e.WriteType(NtType.Unassigned);
            Assert.That(e.Count, Is.EqualTo(0));
            Assert.That(e.Error, Is.EqualTo("unrecognized Type"));

            e.Reset();
            e.WriteType(NtType.Raw);
            Assert.That(e.Count, Is.EqualTo(0));
            Assert.That(e.Error, Is.EqualTo("raw type not supported in protocol < 3.0"));

            e.Reset();
            e.WriteType(NtType.Rpc);
            Assert.That(e.Count, Is.EqualTo(0));
            Assert.That(e.Error, Is.EqualTo("RPC type not supported in protocol < 3.0"));
        }
Exemplo n.º 5
0
        public void WriteBooleanArrayValue3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_boolArray);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 3));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[] { 0x03, 0x00, 0x01, 0x00 }));

            e.Reset();
            e.WriteValue(v_boolArrayBig);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 255));
            Assert.That(new[] { e.Buffer[0], e.Buffer[1] }, Is.EquivalentTo(new byte[] { 0xff, 0x00 }));
        }
Exemplo n.º 6
0
        private void WriteThreadMain()
        {
            WireEncoder encoder = new WireEncoder(ProtoRev);

            while (Active)
            {
                var msgs = m_outgoing.Take();
                Debug4("write thread woke up");
                if (msgs.Count == 0)
                {
                    continue;
                }
                encoder.ProtoRev = ProtoRev;
                encoder.Reset();
                Debug3($"sending {msgs.Count} messages");
                foreach (var message in msgs)
                {
                    if (message != null)
                    {
                        Debug3($"sending type={message.Type} with str={message.Str} id={message.Id} seqNum={message.SeqNumUid}");
                        message.Write(encoder);
                    }
                }
                if (m_stream == null)
                {
                    break;
                }
                if (encoder.Count == 0)
                {
                    continue;
                }
                if (m_stream.Send(encoder.Buffer, 0, encoder.Count) == 0)
                {
                    break;
                }
                Debug4($"sent {encoder.Count} bytes");
            }
            Debug2($"write thread died ({this})");
            if (m_state != State.Dead)
            {
                m_notifier.NotifyConnection(false, GetConnectionInfo());
            }
            m_state = State.Dead;
            Active  = false;
            m_stream?.Dispose(); // Also kill read thread
        }
Exemplo n.º 7
0
        public void WriteStringArrayValue3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_stringArray);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 6 + 8));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[]
            {
                0x02, 0x05, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o',
                0x07, (byte)'g', (byte)'o', (byte)'o', (byte)'d', (byte)'b', (byte)'y', (byte)'e'
            }));

            e.Reset();
            e.WriteValue(v_stringArrayBig);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 255 * 2));
            Assert.That(new[] { e.Buffer[0], e.Buffer[1] }, Is.EquivalentTo(new byte[] { 0xff, 0x01 }));
        }
Exemplo n.º 8
0
        public void WriteDoubleArrayValue3()
        {
            WireEncoder e = new WireEncoder(0x0300);

            e.WriteValue(v_doubleArray);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 2 * 8));
            Assert.That(e.Buffer, Is.EquivalentTo(new byte[]
            {
                0x02, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x3f, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            }));

            e.Reset();
            e.WriteValue(v_doubleArrayBig);
            Assert.That(e.Error, Is.Null);
            Assert.That(e.Buffer.Length, Is.EqualTo(1 + 255 * 8));
            Assert.That(new[] { e.Buffer[0], e.Buffer[1] }, Is.EquivalentTo(new byte[] { 0xff, 0x00 }));
        }