Ejemplo n.º 1
0
    public static UInt64 ReadUInt64(this BitStreamReader reader)
    {
        UInt32 left  = reader.ReadUInt32();
        UInt32 right = reader.ReadUInt32();

        return(BitConverterX.UInt32ToUInt64(left, right));
    }
Ejemplo n.º 2
0
        public static async Task <int> GetLengthAsync(this NetworkStream stream)
        {
            byte[] length_buffer = new byte[2];
            int    byteCount     = stream.ReadAsync(length_buffer, 0, 2).Result;

            if (byteCount != 2)
            {
                return(0);
            }
            return(BitConverterX.ToInt16(length_buffer, 0));
        }
Ejemplo n.º 3
0
        public static int GetLength(this NetworkStream stream)
        {
            byte[] length_buffer = new byte[2];
            int    byteCount     = stream.Read(length_buffer, 0, 2);

            if (byteCount != 2)
            {
                return(0);
            }
            return(BitConverterX.ToInt16(length_buffer, 0));
        }
Ejemplo n.º 4
0
        private static T[] GetNumbersSingle <T>(IReadOnlyList <IGenotype> parents, int offset)
        {
            var result = new T[parents.Count];

            for (var i = 0; i < result.Length; i++)
            {
                result[i] = BitConverterX.ToValue <T>(parents[i].Genes, offset);
            }

            return(result);
        }
Ejemplo n.º 5
0
    public WorldModuleTickRandom(uint tickId, uint seed)
    {
        _randomFromTick = new FixRandom(BitConverterX.UInt32ToInt32(((tickId + 1) * 99877) + seed));

        uint mod = tickId % 7;

        for (int i = 0; i < mod; i++)
        {
            _randomFromTick.NextUInt();
        }
    }
Ejemplo n.º 6
0
        internal byte[] GetGatewayResponse()
        {
            int?bytesReceived = 0;

            byte[] buffer        = new byte[2048];
            int    position      = 0;
            int    messageLength = 0;
            var    t             = DateTime.Now;
            int    length;

            do
            {
                if (messageLength == 0)
                {
                    byte[] lengthBuffer = new byte[2];
                    length = sslStream.ReadAsync(lengthBuffer, 0, lengthBuffer.Length).Result;
                    if (length == 2)
                    {
                        messageLength = BitConverterX.ToInt16(lengthBuffer, 0) - 2;
                    }
                }
                if (messageLength != 0)
                {
                    int currLength = sslStream.ReadAsync(buffer, position, messageLength).Result;
                    if (currLength == messageLength)
                    {
                        bytesReceived = messageLength;
                    }
                    else
                    {
                        position += currLength;
                    }
                }
            } while ((DateTime.Now - t).TotalMilliseconds <= 20000 && bytesReceived == 0);
            if (bytesReceived > 0)
            {
                byte[] rec_buffer = new byte[(int)bytesReceived];
                Array.Copy(buffer, 0, rec_buffer, 0, (int)bytesReceived);
                return(rec_buffer);
            }
            throw new GatewayTimeoutException();
        }
Ejemplo n.º 7
0
 public static Single ReadFloat32(this BitStreamReader reader)
 {
     return(BitConverterX.Int32ToFloat32(reader.ReadBits(32)));
 }
Ejemplo n.º 8
0
 public static UInt32 ReadUInt32(this BitStreamReader reader)
 {
     return(BitConverterX.Int32ToUInt32(reader.ReadBits(32)));
 }
Ejemplo n.º 9
0
 public static UInt16 ReadUInt16(this BitStreamReader reader)
 {
     return((UInt16)BitConverterX.Int32ToUInt32(reader.ReadBits(16)));
 }
 public virtual T GetValue()
 {
     return(BitConverterX.ToValue <T>(Genotype.Genes));
 }
Ejemplo n.º 11
0
 public static void WriteFloat32(this BitStreamWriter writer, Single value)
 {
     writer.WriteBits(BitConverterX.Float32ToUInt32(value), 32);
 }
Ejemplo n.º 12
0
 public static void WriteUInt64(this BitStreamWriter writer, UInt64 value)
 {
     BitConverterX.UInt64ToUInt32(value, out UInt32 left, out UInt32 right);
     writer.WriteUInt32(left);
     writer.WriteUInt32(right);
 }
Ejemplo n.º 13
0
 public static void WriteInt32(this BitStreamWriter writer, Int32 value)
 {
     writer.WriteBits(BitConverterX.Int32ToUInt32(value), 32);
 }