public double DecodeFloat64(byte[] bytes, Iterator it)
        {
            double value = bitConverter.ToDouble(bytes, it.Offset);

            it.Offset += 8;
            return(value);
        }
        public void ToXXX()
        {
            var sut = new LittleEndianBitConverter();

            var data = new byte[] { 0x03, 0, 0, 0, 0, 0, 0, 0 };

            Check.That(sut.ToBoolean(data, 0)).IsTrue();
            Check.That(sut.ToBoolean(data, 7)).IsFalse();
            Check.That(sut.ToChar(data, 0)).IsEqualTo('\u0003');
            Check.That(sut.ToChar(data, 6)).IsEqualTo('\0');
            Check.That(sut.ToInt16(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt16(data, 6)).IsEqualTo(0);
            Check.That(sut.ToUInt16(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt16(data, 6)).IsEqualTo(0u);
            Check.That(sut.ToInt32(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt32(data, 4)).IsEqualTo(0);
            Check.That(sut.ToUInt32(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt32(data, 4)).IsEqualTo(0u);
            Check.That(sut.ToInt64(data, 0)).IsEqualTo(3L);
            Check.That(sut.ToUInt64(data, 0)).IsEqualTo(3UL);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x20, 0x41 };
            Check.That(sut.ToSingle(data, 0)).IsEqualTo(0.0f);
            Check.That(sut.ToSingle(data, 4)).IsEqualTo(10.0f);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x24, 0x40 };
            Check.That(sut.ToDouble(data, 0)).IsEqualTo(10.0);
        }
        public void LittleEndianBitConverter_Double()
        {
            const int n = sizeof(Double);

            const Double pos  = Math.PI;
            const Double zero = 0;
            const Double neg  = -pos;

            var posRepr = GetCanonicalRepresentation(pos);
            var negRepr = GetCanonicalRepresentation(neg);

            // --------------------------------------------------------------

            var buffer = new byte[n];

            LittleEndianBitConverter.FillBytes(pos, buffer);
            Assert.IsTrue(buffer.SequenceEqual(posRepr));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(pos).SequenceEqual(buffer));
            Assert.AreEqual(pos, LittleEndianBitConverter.ToDouble(buffer));

            LittleEndianBitConverter.FillBytes(zero, buffer);
            Assert.IsTrue(buffer.SequenceEqual(new byte[n]));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(zero).SequenceEqual(buffer));
            Assert.AreEqual(zero, LittleEndianBitConverter.ToDouble(buffer));

            LittleEndianBitConverter.FillBytes(neg, buffer);
            Assert.IsTrue(buffer.SequenceEqual(negRepr));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(neg).SequenceEqual(buffer));
            Assert.AreEqual(neg, LittleEndianBitConverter.ToDouble(buffer));
        }
Beispiel #4
0
        public unsafe double imethod_42()
        {
            double num;

            fixed(byte *pointer = this.byte_6)
            {
                this.method_2(pointer);
                num = LittleEndianBitConverter.ToDouble(this.byte_6);
            }

            return(num);
        }
Beispiel #5
0
 public static double smethod_8(Stream stream)
 {
     byte[] numArray = new byte[8];
     stream.Read(numArray, 0, 8);
     return(LittleEndianBitConverter.ToDouble(numArray, 0));
 }
Beispiel #6
0
        private void DispatchPacket(AgarPacket p)
        {
            Console.WriteLine("Received {0} packet with {1} bytes of data.", (ServerPacketType)p.OpCode, p.Payload.Length);

            switch ((ServerPacketType)p.OpCode)
            {
            case ServerPacketType.GameAreaSize:
                // TODO Assert PayloadLength == 32
                double min_x = bc.ToDouble(p.Payload, 0);
                double min_y = bc.ToDouble(p.Payload, 8);
                double max_x = bc.ToDouble(p.Payload, 16);
                double max_y = bc.ToDouble(p.Payload, 24);
                world.SetBounds(min_x, min_y, max_x, max_y);
                break;

            case ServerPacketType.WorldUpdate:
                // Read eat events
                uint       count = bc.ToUInt16(p.Payload, 0);
                EatEvent[] eats  = new EatEvent[count];
                for (int i = 0; i < count; i++)
                {
                    eats[i] = new EatEvent()
                    {
                        eater_id  = bc.ToUInt32(p.Payload, i * 8),
                        victim_id = bc.ToUInt32(p.Payload, i * 8 + 4)
                    };
                }

                // Read cell updates (names, size, position)
                List <UpdateEvent> updates = new List <UpdateEvent>();
                UpdateEvent        current;
                int offset = 0;

                while (true)
                {
                    current.blob_id = bc.ToUInt32(p.Payload, offset);
                    if (current.blob_id == 0)
                    {
                        break;
                    }

                    current.x = bc.ToUInt32(p.Payload, offset + 4);
                    current.y = bc.ToUInt32(p.Payload, offset + 8);

                    current.radius = bc.ToUInt16(p.Payload, offset + 10);
                    current.red    = p.Payload[offset + 11];
                    current.green  = p.Payload[offset + 12];
                    current.blue   = p.Payload[offset + 13];
                    current.flags  = p.Payload[offset + 14];

                    if ((current.flags & 0x02) != 0)
                    {
                        offset += 4;         // Unsure about this...
                    }
                    current.skin_url = null; // Just to fully initialize the struct

                    if ((current.flags & 0x04) != 0)
                    {
                        current.skin_url = bc.ToNullStr8(p.Payload, offset + 15, ref offset);     // Will increment offset by num bytes
                    }
                    current.name = bc.ToNullStr16(p.Payload, offset + 15, ref offset);

                    updates.Add(current);
                }

                // Read cell removals (out of sight, disconnect, etc)
                count = bc.ToUInt32(p.Payload, offset + 15);
                uint[] removals = new uint[count];
                for (int i = 0; i < count; i++)
                {
                    removals[i] = bc.ToUInt32(p.Payload, offset + 17 + i * 4);
                }

                world.RegisterEats(eats);
                world.RegisterUpdates(updates);
                world.RegisterRemovals(removals);

                break;

            case ServerPacketType.FFALeaderboard:
                count  = bc.ToUInt32(p.Payload, 0);
                offset = 4;
                for (uint i = 0; i < count; i++)
                {
                    uint   blob_id = bc.ToUInt32(p.Payload, offset); offset += 4;
                    string name    = bc.ToNullStr16(p.Payload, offset, ref offset);

                    // We got the data, add it to a list or something. TODO create a leaderboard class
                }
                break;
            }
        }
Beispiel #7
0
        public unsafe double imethod_29(double defaultValue)
        {
            byte num1 = this.imethod_13();

            switch (num1)
            {
            case 0:
                return(defaultValue);

            case 1:
                byte[] bytes1 = LittleEndianBitConverter.GetBytes(defaultValue);
                fixed(byte *numPtr1 = bytes1)
                {
                    if (this.int_0 == 0)
                    {
                        this.method_6();
                        numPtr1[0] = this.byte_3;
                        byte *numPtr2 = numPtr1 + 1;
                        this.method_6();
                        *     numPtr2 = this.byte_3;
                        byte *numPtr3 = numPtr2 + 1;
                        this.method_6();
                        *     numPtr3 = this.byte_3;
                        byte *numPtr4 = numPtr3 + 1;
                        this.method_6();
                        *numPtr4 = this.byte_3;
                    }
                    else
                    {
                        numPtr1[0] = (byte)((uint)this.byte_3 << this.int_0);
                        this.method_6();
                        byte *numPtr2 = numPtr1;
                        int   num2    = (int)(byte)((uint)*numPtr2 | (uint)(byte)((uint)this.byte_3 >> 8 - this.int_0));
                        *     numPtr2 = (byte)num2;
                        byte *numPtr3 = numPtr1 + 1;
                        *     numPtr3 = (byte)((uint)this.byte_3 << this.int_0);
                        this.method_6();
                        byte *numPtr4 = numPtr3;
                        int   num3    = (int)(byte)((uint)*numPtr4 | (uint)(byte)((uint)this.byte_3 >> 8 - this.int_0));
                        *     numPtr4 = (byte)num3;
                        byte *numPtr5 = numPtr3 + 1;
                        *     numPtr5 = (byte)((uint)this.byte_3 << this.int_0);
                        this.method_6();
                        byte *numPtr6 = numPtr5;
                        int   num4    = (int)(byte)((uint)*numPtr6 | (uint)(byte)((uint)this.byte_3 >> 8 - this.int_0));
                        *     numPtr6 = (byte)num4;
                        byte *numPtr7 = numPtr5 + 1;
                        *     numPtr7 = (byte)((uint)this.byte_3 << this.int_0);
                        this.method_6();
                        byte *numPtr8 = numPtr7;
                        int   num5    = (int)(byte)((uint)*numPtr8 | (uint)(byte)((uint)this.byte_3 >> 8 - this.int_0));
                        *     numPtr8 = (byte)num5;
                    }
                }

                return(LittleEndianBitConverter.ToDouble(bytes1));

            case 2:
                byte[] bytes2 = LittleEndianBitConverter.GetBytes(defaultValue);
                if (this.int_0 == 0)
                {
                    this.method_6();
                    bytes2[4] = this.byte_3;
                    this.method_6();
                    bytes2[5] = this.byte_3;
                    this.method_6();
                    bytes2[0] = this.byte_3;
                    this.method_6();
                    bytes2[1] = this.byte_3;
                    this.method_6();
                    bytes2[2] = this.byte_3;
                    this.method_6();
                    bytes2[3] = this.byte_3;
                }
                else
                {
                    bytes2[4] = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[4] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                    bytes2[5]  = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[5] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                    bytes2[0]  = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[0] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                    bytes2[1]  = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[1] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                    bytes2[2]  = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[2] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                    bytes2[3]  = (byte)((uint)this.byte_3 << this.int_0);
                    this.method_6();
                    bytes2[3] |= (byte)((uint)this.byte_3 >> 8 - this.int_0);
                }
                return(LittleEndianBitConverter.ToDouble(bytes2));

            case 3:
                return(this.imethod_42());

            default:
                throw new DxfException("Illegal double type. " + num1.ToString());
            }
        }
Beispiel #8
0
        /// <summary>
        /// Read data from stream
        /// </summary>
        /// <param name="s">stream</param>
        /// <returns>data of specified type</returns>
        public static double ToDouble(Stream s)
        {
            byte[] buf = GetBytes(s, sizeof(ulong));

            return(LittleEndianBitConverter.ToDouble(buf, 0));
        }