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));
        }
        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);
        }
Exemple #3
0
        public unsafe int imethod_11()
        {
            int num;

            switch (this.imethod_13())
            {
            case 0:
                fixed(byte *pointer = this.byte_5)
                {
                    this.method_1(pointer);
                    num = LittleEndianBitConverter.ToInt32(this.byte_5);
                }

                break;

            case 1:
                if (this.int_0 == 0)
                {
                    this.method_6();
                    num = (int)this.byte_3;
                    break;
                }
                num = (int)this.method_7();
                break;

            case 2:
                num = 0;
                break;

            default:
                throw new DxfException("Illegal int.");
            }
            return(num);
        }
Exemple #4
0
 public void Write()
 {
     this.stream_0.Write(Class328.byte_0, 0, Class328.byte_0.Length);
     this.stream_0.Write(LittleEndianBitConverter.GetBytes(1), 0, 4);
     this.stream_0.WriteByte((byte)0);
     this.stream_0.Write(Class328.byte_1, 0, Class328.byte_1.Length);
 }
        public void LittleEndianBitConverter_Int32()
        {
            const int n = sizeof(Int32);

            const Int32 pos  = 0x11223344;
            const Int32 zero = 0;
            const Int32 neg  = -pos;

            var posRepr = new byte[] { 0x44, 0x33, 0x22, 0x11 };

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

            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.ToInt32(buffer));

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

            LittleEndianBitConverter.FillBytes(neg, buffer);
            Assert.IsTrue(buffer.SequenceEqual(Neg(posRepr)));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(neg).SequenceEqual(buffer));
            Assert.AreEqual(neg, LittleEndianBitConverter.ToInt32(buffer));
        }
        public void LittleEndianBitConverter_Decimal()
        {
            const int n = sizeof(Decimal);

            const Decimal pos  = 3.1415926535897932384626433833m;
            const Decimal zero = 0;
            const Decimal 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.ToDecimal(buffer));

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

            LittleEndianBitConverter.FillBytes(neg, buffer);
            Assert.IsTrue(buffer.SequenceEqual(negRepr));
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(neg).SequenceEqual(buffer));
            Assert.AreEqual(neg, LittleEndianBitConverter.ToDecimal(buffer));
        }
        public static List <byte[]> SplitData(
            byte[] data,
            int blockSize
            )
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentNullException();
            }
            if (blockSize <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            uint blockCount            = GetBlocksCount((uint)data.Length, (uint)blockSize);
            var  result                = new List <byte[]>();
            var  inStream              = new MemoryStream(data);
            var  littleEndianConverter = new LittleEndianBitConverter();
            var  binaryReader          = new EndianBinaryReader(
                littleEndianConverter,
                inStream
                );

            for (int i = 0; i < blockCount; i++)
            {
                var elem = binaryReader.ReadBytes(blockSize);
                result.Add(elem);
            }
            return(result);
        }
Exemple #8
0
        public Class995()
        {
            Random random = new Random();

            byte[] numArray = new byte[8];
            random.NextBytes(numArray);
            this.method_0(LittleEndianBitConverter.ToUInt64(numArray));
        }
Exemple #9
0
 public void Write(Stream stream)
 {
     stream.Write(LittleEndianBitConverter.GetBytes(this.ulong_0), 0, 8);
     stream.Write(LittleEndianBitConverter.GetBytes(this.ulong_1), 0, 8);
     stream.Write(LittleEndianBitConverter.GetBytes(this.ulong_2), 0, 8);
     stream.Write(LittleEndianBitConverter.GetBytes(this.ulong_3), 0, 8);
     stream.Write(LittleEndianBitConverter.GetBytes(this.ulong_4), 0, 8);
 }
        public void ToXXX_ThrowsOnInvalidIndexOrSize()
        {
            var sut = new LittleEndianBitConverter();

            var data = new byte[3];

            Check.ThatCode(() => sut.ToInt32(data, 0)).Throws <ArgumentOutOfRangeException>();

            data = new byte[4];
            Check.ThatCode(() => sut.ToInt32(data, 1)).Throws <ArgumentOutOfRangeException>();
        }
Exemple #11
0
        public AgarClient(DefaultPacketManager pm)
        {
            world           = new AgarWorld();
            bc              = new LittleEndianBitConverter();
            wait_useraction = new AutoResetEvent(false);

            pacman = pm;

            userActions_l = new object();
            userActions   = new Queue <AgarPacket>();
        }
        public void GetBytes()
        {
            var sut = new LittleEndianBitConverter();

            Check.That(new byte[] { 0 }).ContainsExactly(sut.GetBytes(false));
            Check.That(new byte[] { 1 }).ContainsExactly(sut.GetBytes(true));

            Check.That(new byte[] { 0, 0 }).ContainsExactly(sut.GetBytes((short)0));
            Check.That(new byte[] { 1, 0 }).ContainsExactly(sut.GetBytes((short)1));
            Check.That(new byte[] { 0, 1 }).ContainsExactly(sut.GetBytes((short)256));
            Check.That(new byte[] { 255, 255 }).ContainsExactly(sut.GetBytes((short)-1));

            Check.That(new byte[] { 0, 0 }).ContainsExactly(sut.GetBytes((ushort)0));
            Check.That(new byte[] { 1, 0 }).ContainsExactly(sut.GetBytes((ushort)1));
            Check.That(new byte[] { 0, 1 }).ContainsExactly(sut.GetBytes((ushort)256));
            Check.That(new byte[] { 255, 255 }).ContainsExactly(sut.GetBytes(ushort.MaxValue));

            Check.That(new byte[] { 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(0));
            Check.That(new byte[] { 1, 0, 0, 0 }).ContainsExactly(sut.GetBytes(1));
            Check.That(new byte[] { 0, 1, 0, 0 }).ContainsExactly(sut.GetBytes(256));
            Check.That(new byte[] { 0, 0, 1, 0 }).ContainsExactly(sut.GetBytes(65536));
            Check.That(new byte[] { 0, 0, 0, 1 }).ContainsExactly(sut.GetBytes(16777216));
            Check.That(new byte[] { 255, 255, 255, 255 }).ContainsExactly(sut.GetBytes(-1));

            Check.That(new byte[] { 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(0u));
            Check.That(new byte[] { 1, 0, 0, 0 }).ContainsExactly(sut.GetBytes(1u));
            Check.That(new byte[] { 0, 1, 0, 0 }).ContainsExactly(sut.GetBytes(256u));
            Check.That(new byte[] { 0, 0, 1, 0 }).ContainsExactly(sut.GetBytes(65536u));
            Check.That(new byte[] { 0, 0, 0, 1 }).ContainsExactly(sut.GetBytes(16777216u));
            Check.That(new byte[] { 255, 255, 255, 255 }).ContainsExactly(sut.GetBytes(uint.MaxValue));

            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(0L));
            Check.That(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(1L));
            Check.That(new byte[] { 0, 1, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(256L));
            Check.That(new byte[] { 0, 0, 1, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(65536L));
            Check.That(new byte[] { 0, 0, 0, 1, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(16777216L));
            Check.That(new byte[] { 0, 0, 0, 0, 1, 0, 0, 0 }).ContainsExactly(sut.GetBytes(4294967296L));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 1, 0, 0 }).ContainsExactly(sut.GetBytes(1099511627776L));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 1, 0 }).ContainsExactly(sut.GetBytes(281474976710656L));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }).ContainsExactly(sut.GetBytes(72057594037927936L));
            Check.That(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }).ContainsExactly(sut.GetBytes(-1L));

            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(0UL));
            Check.That(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(1UL));
            Check.That(new byte[] { 0, 1, 0, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(256UL));
            Check.That(new byte[] { 0, 0, 1, 0, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(65536UL));
            Check.That(new byte[] { 0, 0, 0, 1, 0, 0, 0, 0 }).ContainsExactly(sut.GetBytes(16777216UL));
            Check.That(new byte[] { 0, 0, 0, 0, 1, 0, 0, 0 }).ContainsExactly(sut.GetBytes(4294967296UL));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 1, 0, 0 }).ContainsExactly(sut.GetBytes(1099511627776UL));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 1, 0 }).ContainsExactly(sut.GetBytes(281474976710656UL));
            Check.That(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }).ContainsExactly(sut.GetBytes(72057594037927936UL));
            Check.That(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }).ContainsExactly(sut.GetBytes(ulong.MaxValue));
        }
Exemple #13
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);
        }
Exemple #14
0
        public unsafe ulong imethod_46()
        {
            ulong uint64;

            fixed(byte *pointer = this.byte_6)
            {
                this.method_2(pointer);
                uint64 = LittleEndianBitConverter.ToUInt64(this.byte_6);
            }

            return(uint64);
        }
Exemple #15
0
        public unsafe int imethod_43()
        {
            int int32;

            fixed(byte *pointer = this.byte_5)
            {
                this.method_1(pointer);
                int32 = LittleEndianBitConverter.ToInt32(this.byte_5);
            }

            return(int32);
        }
Exemple #16
0
        public unsafe ushort method_4()
        {
            ushort uint16;

            fixed(byte *pointer = this.byte_5)
            {
                this.method_0(pointer);
                uint16 = LittleEndianBitConverter.ToUInt16(this.byte_5);
            }

            return(uint16);
        }
Exemple #17
0
        public unsafe uint imethod_44()
        {
            uint uint32;

            fixed(byte *pointer = this.byte_5)
            {
                this.method_1(pointer);
                uint32 = LittleEndianBitConverter.ToUInt32(this.byte_5);
            }

            return(uint32);
        }
Exemple #18
0
        public unsafe short imethod_45()
        {
            short int16;

            fixed(byte *pointer = this.byte_5)
            {
                this.method_0(pointer);
                int16 = LittleEndianBitConverter.ToInt16(this.byte_5);
            }

            return(int16);
        }
Exemple #19
0
 public override void imethod_5(string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         this.imethod_13(LittleEndianBitConverter.GetBytes((ushort)0), 0, 2);
     }
     else
     {
         this.imethod_13(LittleEndianBitConverter.GetBytes((ushort)value.Length), 0, 2);
         byte[] bytes = Encoding.Unicode.GetBytes(value);
         this.imethod_13(bytes, 0, bytes.Length);
     }
 }
        public void LittleEndianBitConverter_Boolean()
        {
            var buffer = new byte[1];

            LittleEndianBitConverter.FillBytes(true, buffer);
            Assert.AreEqual(1, buffer[0]);
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(true).SequenceEqual(buffer));
            Assert.AreEqual(true, LittleEndianBitConverter.ToBoolean(buffer));

            LittleEndianBitConverter.FillBytes(false, buffer);
            Assert.AreEqual(0, buffer[0]);
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(false).SequenceEqual(buffer));
            Assert.AreEqual(false, LittleEndianBitConverter.ToBoolean(buffer));
        }
Exemple #21
0
 /// <summary>
 /// Write value to stream.
 /// </summary>
 /// <param name="s">stream</param>
 /// <param name="value">value</param>
 static public void Write(Stream s, byte[] value)
 {
     if (value == null)
     {
         byte[] lenBuf = LittleEndianBitConverter.GetBytes((int)0);//data length
     }
     else
     {
         byte[] buf    = value;
         byte[] lenBuf = LittleEndianBitConverter.GetBytes((int)buf.Length);
         s.Write(lenBuf, 0, lenBuf.Length); //data length
         s.Write(buf, 0, buf.Length);
     }
 }
Exemple #22
0
 public void imethod_16(double value)
 {
     if (value == 0.0)
     {
         this.imethod_15((byte)2);
     }
     else if (value == 1.0)
     {
         this.imethod_15((byte)1);
     }
     else
     {
         this.imethod_15((byte)0);
         this.imethod_12(LittleEndianBitConverter.GetBytes(value));
     }
 }
Exemple #23
0
        private unsafe ulong method_3(int count)
        {
            if (this.stream_0.Read(this.byte_7, 0, count) < count)
            {
                throw new EndOfStreamException();
                fixed(byte *numPtr1 = this.byte_6)
                {
                    if (this.int_0 == 0)
                    {
                        byte *numPtr2 = numPtr1 + count - 1;
                        fixed(byte *numPtr3 = this.byte_7)
                        {
                            byte *numPtr4 = numPtr3;

                            for (int index = 0; index < count; ++index)
                            {
                                *numPtr2-- = *numPtr4++;
                            }
                        }
                    }
                    else
                    {
                        int   num1    = 8 - this.int_0;
                        byte *numPtr2 = numPtr1 + count - 1;
                        fixed(byte *numPtr3 = this.byte_7)
                        {
                            byte *numPtr4 = numPtr3;

                            for (int index = 0; index < count; ++index)
                            {
                                byte num2 = (byte)((uint)this.byte_3 << this.int_0);
                                this.byte_3 = *numPtr4++;
                                byte num3      = (byte)((uint)num2 | (uint)(byte)((uint)this.byte_3 >> num1));
                                *    numPtr2-- = num3;
                            }
                        }
                    }
                    byte *numPtr5 = numPtr1 + count;

                    for (int index = count; index < 8; ++index)
                    {
                        *numPtr5++ = (byte)0;
                    }
                }

                return(LittleEndianBitConverter.ToUInt64(this.byte_6));
        }
Exemple #24
0
        public DefaultPacketManager()
        {
            this_lock = new object();

            websock = new ClientWebSocket();

            bc = new LittleEndianBitConverter();

            in_packets_l    = new object();
            in_packets      = new Queue <AgarPacket>();
            packet_received = new AutoResetEvent(false);

            out_packets_l = new object();
            out_packets   = new Queue <AgarPacket>();
            packet_sent   = new AutoResetEvent(false);

            hasStarted = false;
        }
Exemple #25
0
        /// <summary>
        /// Read data from stream
        /// </summary>
        /// <param name="s">stream</param>
        /// <returns>data of specified type</returns>
        public static byte[] ToData(Stream s)
        {
            byte[] lenBuf = new byte[sizeof(int)];

            s.Read(lenBuf, 0, lenBuf.Length);

            int len = LittleEndianBitConverter.ToInt32(lenBuf, 0);

            if (len == 0)
            {
                return(null);
            }
            else
            {
                byte[] buf = new byte[len];
                s.Read(buf, 0, len);
                return(buf);
            }
        }
Exemple #26
0
        /// <summary>
        /// Read data from stream
        /// </summary>
        /// <param name="s">stream</param>
        /// <returns>data of specified type</returns>
        public static string ToString(Stream s)
        {
            byte[] lenBuf = new byte[sizeof(int)];

            s.Read(lenBuf, 0, lenBuf.Length);

            int len = LittleEndianBitConverter.ToInt32(lenBuf, 0);

            if (len == 0)
            {
                return(null);
            }
            else
            {
                byte[] buf = new byte[len];
                s.Read(buf, 0, len);
                return(Encoding.UTF8.GetString(buf, 0, buf.Length));
            }
        }
Exemple #27
0
        private void ReadHeader()
        {
            ReadIdentificator();
            EndianBitConverter converter;

            if (Endianess == Endianess.LittleEndian)
            {
                converter = new LittleEndianBitConverter();
            }
            else
            {
                converter = new BigEndianBitConverter();
            }
            readerSource = () => new EndianBinaryReader(
                converter,
                GetNewStream()
                );
            localReaderSource = () => new EndianBinaryReader(converter, new NonClosingStreamWrapper(stream));
            ReadFields();
        }
Exemple #28
0
        private void method_12()
        {
            int          sectionStartPosition1 = (int)Class653.smethod_0(this.int_0);
            int          num1 = sectionStartPosition1 + (int)this.memoryStream_0.Length;
            int          sectionStartPosition2 = num1 + (int)this.memoryStream_4.Length;
            int          sectionStartPosition3 = sectionStartPosition2 + (int)this.memoryStream_1.Length;
            int          sectionStartPosition4 = sectionStartPosition3 + (int)this.memoryStream_2.Length + (int)this.memoryStream_3.Length + (int)this.memoryStream_5.Length;
            int          sectionStartPosition5 = sectionStartPosition4 + (int)this.memoryStream_6.Length + (int)this.memoryStream_7.Length;
            MemoryStream memoryStream          = new MemoryStream();
            Interface29  streamWriter          = Class724.Create(this.dxfVersion_0, (Stream)memoryStream, Encodings.GetEncoding((int)this.dxfModel_0.Header.DrawingCodePage));

            streamWriter.imethod_13(Encodings.Ascii.GetBytes(this.dxfModel_0.Header.AcadVersionString), 0, 6);
            Interface29 nterface29 = streamWriter;

            byte[] numArray = new byte[7];
            numArray[5] = (byte)15;
            numArray[6] = (byte)1;
            byte[] bytes = numArray;
            nterface29.imethod_12(bytes);
            streamWriter.imethod_19(num1);
            streamWriter.imethod_11((byte)27);
            streamWriter.imethod_11((byte)25);
            int num2 = (int)Class952.smethod_1(this.dxfModel_0.Header.DrawingCodePage);

            streamWriter.imethod_13(LittleEndianBitConverter.GetBytes((short)num2), 0, 2);
            streamWriter.imethod_13(LittleEndianBitConverter.GetBytes(this.int_0), 0, 4);
            long position = this.stream_0.Position;

            this.method_13(streamWriter, (byte)0, sectionStartPosition2, (int)this.memoryStream_1.Length);
            this.method_13(streamWriter, (byte)1, sectionStartPosition3, (int)this.memoryStream_2.Length);
            this.method_13(streamWriter, (byte)2, sectionStartPosition4, (int)this.memoryStream_6.Length);
            this.method_13(streamWriter, (byte)3, 0, 0);
            this.method_13(streamWriter, (byte)4, sectionStartPosition5, (int)this.memoryStream_9.Length);
            this.method_13(streamWriter, (byte)5, sectionStartPosition1, (int)this.memoryStream_0.Length);
            streamWriter.Flush();
            ushort num3 = Stream1.smethod_1((ushort)49345, memoryStream.GetBuffer(), 0L, memoryStream.Length);

            streamWriter.imethod_18((short)num3);
            streamWriter.imethod_13(Class800.byte_4, 0, Class800.byte_4.Length);
            this.stream_0.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
        }
Exemple #29
0
        public Class921(Stream stream, DxfModel model)
        {
            if (!stream.CanSeek || !stream.CanWrite)
            {
                throw new ArgumentException("Stream must allow writing and seeking.");
            }
            this.dxfModel_0   = model;
            this.stream_0     = stream;
            this.dxfVersion_0 = model.Header.AcadVersion;
            this.encoding_0   = Encodings.GetEncoding((int)model.Header.DrawingCodePage);
            Random random = new Random();

            byte[] numArray = new byte[8];
            random.NextBytes(numArray);
            this.class995_0.method_0(LittleEndianBitConverter.ToUInt64(numArray));
            this.uint_0 = 0U;
            this.class954_0.RandomSeed         = this.class995_0.Seed;
            this.class954_0.CrcSeed            = (ulong)this.uint_0;
            this.class954_0.PagesMapCrcSeed    = (ulong)this.uint_0;
            this.class954_0.SectionsMapCrcSeed = (ulong)this.uint_0;
        }
Exemple #30
0
        private void ProcInnerMessage(Event.ReceiveEventArgs message)
        {
            try
            {
                switch ((InnerEvent)message.Event)
                {
                case InnerEvent.GetProcessorId:
                {
                    //Get processorid and cableid
                    //Only syncronize connection of single connection cable will
                    //Send this event to server to alloc

                    //Processor mask from client
                    ulong mask = LittleEndianBitConverter.ToUInt64(message.Data, 0);

                    //Get Processor id
                    int pId = _AllocClientProcessor.GetProcessorId(((IPEndPoint)message.RemoteIPEndPoint).Address,
                                                                   mask, message.SCBID);

                    //Get cable id
                    SCB    scb     = GetSCB((IPEndPoint)message.RemoteIPEndPoint);
                    UInt16 cableId = _CableIdAllocator.Alloc(scb.RemoteIPEndPoint);
                    scb.CableId = cableId;

                    message.ReturnData = new byte[sizeof(int) + sizeof(UInt16)];

                    Array.Copy(LittleEndianBitConverter.GetBytes(pId), 0,
                               message.ReturnData, 0, sizeof(int));

                    Array.Copy(LittleEndianBitConverter.GetBytes(cableId), 0,
                               message.ReturnData, sizeof(int), sizeof(UInt16));
                }
                break;
                }
            }
            catch (Exception e)
            {
                OnErrorEvent("ProcInnerMessage", e);
            }
        }
 public static byte[] GetSentTransfer20151004ArgsHmacAuthCode(
     SendTransfer20151004Args request,
     byte[] hmacKey
     )
 {
     Assert.NotNull(request);
     CheckSentTransfer20151004Args(request);
     Assert.NotNull(hmacKey);
     Assert.Equal(hmacKey.Length, 64);
     using (var ms = new MemoryStream())
     {
         var converter = new LittleEndianBitConverter();
         using (var littleStream = new EndianBinaryWriter(converter, ms))
         {
             littleStream.Write(request.RequestGuid.ToByteArray());
             var dt = DateTime.ParseExact(
                 request.SentTimeString,
                 DateTimeStringFormat20151004,
                 CultureInfo.InvariantCulture
             );
             littleStream.Write(dt.Ticks);
             littleStream.Write(request.WalletFromGuid.ToByteArray());
             littleStream.Write(request.WalletToGuid.ToByteArray());
             littleStream.Write(request.Amount);
             littleStream.Write(request.AnonymousTransfer);
             littleStream.Write(request.CommentBytes);
             littleStream.Write(request.MaxFee);
         }
         return new HMACSHA256(hmacKey).ComputeHash(ms.ToArray());
     }
 }