using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PXP.Crawler.API.Utils
{
    public sealed class Conv
    {
        public static double StringToDouble(string val, double defaultValue = 0)
        {
            double v = defaultValue;
            if (double.TryParse(val, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
            {
                return v;
            }
            return defaultValue;
        }

        public static int StringToInt(string val, int defaultValue)
        {
            double v = defaultValue;
            if (double.TryParse(val, NumberStyles.Integer, CultureInfo.InvariantCulture, out v))
            {
                return (int) v;
            }
            return defaultValue;
        }

        public static byte[] SingleData(float v)
        {
            return BitConverter.GetBytes(v);
        }

        public static float SingleFromData(byte[] vData)
        {
            return BitConverter.ToSingle(vData, 0);
        }
    }
}
