using System.Text;
using Unity.Collections;

namespace RebootKit.Engine.Extensions {
    public static class NativeArrayEx {
        public static string ToHexString(this NativeArray<byte> array) {
            if (array.IsCreated) {
                StringBuilder sb = new StringBuilder(array.Length * 3);
                for (int i = 0; i < array.Length; i++) {
                    sb.AppendFormat("{0:X2} ", array[i]);
                }

                return sb.ToString();
            }
            return string.Empty;
        }

        public static string ToHexString(this NativeSlice<byte> slice) {
            StringBuilder sb = new StringBuilder(slice.Length * 3);
            for (int i = 0; i < slice.Length; i++) {
                sb.AppendFormat("{0:X2} ", slice[i]);
            }

            return sb.ToString();
        }
    }
}