private ServiceUuid[] ExtractServices()
        {
            int i = 0;
            List <ServiceUuid> res = null;

            while (i < _data.Length)
            {
                int len = _data[i];
                if (len == 0 || i + len >= _data.Length)
                {
                    break;
                }
                int uuidLen = 0;
                switch (_data[i + 1])
                {
                case 2:
                case 3:             // complete/incomplete 16-bit uids
                    uuidLen = 2;
                    break;

                case 4:
                case 5:             // complete/incomplete 32-bit uuids
                    uuidLen = 4;
                    break;

                case 6:
                case 7:             // complete/incomplete 128-bit uuids
                    uuidLen = 16;
                    break;
                }
                int n = i + 2;
                i += 1 + len;
                if (uuidLen > 0)
                {
                    for (; n + uuidLen <= i; n += uuidLen)
                    {
                        (res ??= new List <ServiceUuid>()).Add(new ServiceUuid(Uuid.FromLE(_data.AsSpan(n, uuidLen))));
                    }
                }
            }
            return(res?.ToArray() ?? Array.Empty <ServiceUuid>());
        }
Example #2
0
 public void FromLE()
 {
     Assert.AreEqual(new Uuid("00112233-4455-6677-8899-AABBCCDDEEFF"),
                     Uuid.FromLE(new byte[] { 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 }));
 }