Exemplo n.º 1
0
 public void ByteBuffer_PutLongChecksLengthAndOffset()
 {
     var buffer = new byte[8];
     var uut = new ByteBuffer(buffer);
     Assert.Throws<ArgumentOutOfRangeException>(() => uut.PutLong(2, 0x010203040A0B0C0D));
 }
Exemplo n.º 2
0
 /// <summary>初始化拒绝接收文件包的其余部分
 /// 	<remark>abu 2008-02-29 </remark>
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitSendFileRejectContent(ByteBuffer buf)
 {
     // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节
     buf.PutLong(0);
     buf.PutChar((char)0);
     buf.Put((byte)0);
     // 我们先尝试UDP方式
     buf.Put((byte)TransferType);
 }
Exemplo n.º 3
0
        public void ByteBuffer_PutLongPopulatesBufferCorrectly()
        {
            var buffer = new byte[8];
            var uut = new ByteBuffer(buffer);
            uut.PutLong(0, 0x010203040A0B0C0D);

            // Ensure Endianness was written correctly
            Assert.AreEqual(0x0D, buffer[0]);
            Assert.AreEqual(0x0C, buffer[1]);
            Assert.AreEqual(0x0B, buffer[2]);
            Assert.AreEqual(0x0A, buffer[3]);
            Assert.AreEqual(0x04, buffer[4]);
            Assert.AreEqual(0x03, buffer[5]);
            Assert.AreEqual(0x02, buffer[6]);
            Assert.AreEqual(0x01, buffer[7]);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 初始化请求发送文件包的其余部分
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitSendFileContent(ByteBuffer buf)
 {
     // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节
     buf.PutLong(0);
     buf.PutChar((char)0);
     buf.Put((byte)0);
     // 我们先尝试UDP方式
     buf.Put((byte)TransferType);
     buf.Put((byte)0x0);
     if (FakeIp)
     {
         buf.PutInt(0);
         buf.PutChar((char)0);
     }
     else
     {
         // 四个字节的发送者IP,这是外部IP
         buf.Put(user.IP);
         // 发送者端口
         buf.PutChar((char)user.Port);
     }
     // 直接端口
     buf.PutUShort(DirectPort);
     buf.PutInt(0);
     buf.PutChar((char)0);
     buf.Put((byte)0x20);
     buf.Put(DELIMIT);
     buf.Put(Utils.Util.GetBytes(FileName));
     buf.Put(DELIMIT);
     buf.Put(Utils.Util.GetBytes(FileSize));
 }
Exemplo n.º 5
0
 /// <summary>初始化同意接收文件包的其余部分
 /// 	<remark>abu 2008-02-29 </remark>
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitSendFileAcceptContent(ByteBuffer buf)
 {
     // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节
     buf.PutLong(0);
     buf.PutChar((char)0);
     buf.Put((byte)0);
     // 我们先尝试UDP方式
     buf.Put((byte)TransferType);
     buf.Put((byte)0x0);
     // 四个字节的发送者IP,这是外部IP
     buf.Put(user.IP);
     // 发送者端口
     buf.PutChar((char)user.Port);
     // 监听端口,含义未知,为连接服务器的端口,先随便写一个值
     buf.PutUShort(DirectPort);
     // 后面全0
     buf.PutInt(0);
     buf.PutChar((char)0);
 }
Exemplo n.º 6
0
 /// <summary>
 /// 初始化IP信息通知包
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitNotifyFilePortUDP(ByteBuffer buf)
 {
     // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节
     buf.PutLong(0);
     buf.PutChar((char)0);
     buf.Put((byte)0);
     // 我们先尝试UDP方式
     buf.Put((byte)TransferType);
     buf.Put((byte)0x0);
     // 四个字节的发送者IP,这是外部IP
     buf.Put(user.IP);
     // 发送者端口
     buf.PutChar((char)user.Port);
     // 监听端口,含义未知,为连接服务器的端口,先随便写一个值
     buf.PutUShort(DirectPort);
     // 真实IP和第二个端口
     buf.Put(LocalIp);
     buf.PutUShort(LocalPort);
 }
Exemplo n.º 7
0
 /// <summary>
 /// 初始化取消发送文件包
 /// </summary>
 /// <param name="buf">The buf.</param>
 private void InitConnectionCanceled(ByteBuffer buf)
 {
     // 17 - 19. 怀疑也和发送消息包相同,但是在这种情况中,这部分没有使用,为全0,一共11个0字节
     buf.PutLong(0);
     buf.PutChar((char)0);
     buf.Put((byte)0);
     // 传输类型
     buf.Put((byte)TransferType);
 }
Exemplo n.º 8
0
        private static void testHet(int level, ByteBuffer b)
        {

            int p = b.Position;
            b.Limit = (b.Capacity);
            Show(level, b);
            output.Write("    put:");

            b.PutChar((char)1);
            b.PutChar((char)char.MaxValue);
            output.Write(" char");

            b.PutShort((short)1);
            b.PutShort((short)short.MaxValue);
            output.Write(" short");

            b.PutInt(1);
            b.PutInt(int.MaxValue);
            output.Write(" int");

            b.PutLong((long)1);
            b.PutLong((long)long.MaxValue);
            output.Write(" long");

            b.PutFloat((float)1);
            b.PutFloat((float)float.MinValue);
            b.PutFloat((float)float.MaxValue);
            output.Write(" float");

            b.PutDouble((double)1);
            b.PutDouble((double)double.MinValue);
            b.PutDouble((double)double.MaxValue);
            output.Write(" double");

            output.WriteLine();
            b.Limit = (b.Position);
            b.Position = (p);
            Show(level, b);
            output.Write("    get:");

            ck(b, b.GetChar(), 1);
            ck(b, b.GetChar(), char.MaxValue);
            output.Write(" char");

            ck(b, b.GetShort(), 1);
            ck(b, b.GetShort(), short.MaxValue);
            output.Write(" short");

            ck(b, b.GetInt(), 1);
            ck(b, b.GetInt(), int.MaxValue);
            output.Write(" int");

            ck(b, b.GetLong(), 1);
            ck(b, b.GetLong(), long.MaxValue);
            output.Write(" long");

            ck(b, (long)b.GetFloat(), 1);
            ck(b, (long)b.GetFloat(), unchecked((long)float.MinValue));
            ck(b, (long)b.GetFloat(), unchecked((long)float.MaxValue));
            output.Write(" float");

            ck(b, (long)b.GetDouble(), 1);
            ck(b, (long)b.GetDouble(), unchecked((long)double.MinValue));
            ck(b, (long)b.GetDouble(), unchecked((long)double.MaxValue));
            output.Write(" double");

            output.WriteLine();
        }