1466 {
1467 int num = 0;
1468 while (num < span.
Length)
1469 {
1470 if (!
state.SequenceInProgress)
1471 {
1472 state.SequenceInProgress = true;
1473 byte b = span[num];
1474 num++;
1475 if ((b & 0x80) == 0)
1476 {
1477 state.AdditionalBytesExpected = 0;
1478 state.CurrentDecodeBits = b & 0x7F;
1479 state.ExpectedValueMin = 0;
1480 }
1481 else
1482 {
1483 if ((b & 0xC0) == 128)
1484 {
1485 return false;
1486 }
1487 if ((b & 0xE0) == 192)
1488 {
1489 state.AdditionalBytesExpected = 1;
1490 state.CurrentDecodeBits = b & 0x1F;
1491 state.ExpectedValueMin = 128;
1492 }
1493 else if ((b & 0xF0) == 224)
1494 {
1495 state.AdditionalBytesExpected = 2;
1496 state.CurrentDecodeBits = b & 0xF;
1497 state.ExpectedValueMin = 2048;
1498 }
1499 else
1500 {
1501 if ((b & 0xF8) != 240)
1502 {
1503 return false;
1504 }
1505 state.AdditionalBytesExpected = 3;
1506 state.CurrentDecodeBits = b & 7;
1507 state.ExpectedValueMin = 65536;
1508 }
1509 }
1510 }
1511 while (
state.AdditionalBytesExpected > 0 && num < span.
Length)
1512 {
1513 byte b2 = span[num];
1514 if ((b2 & 0xC0) != 128)
1515 {
1516 return false;
1517 }
1518 num++;
1519 state.AdditionalBytesExpected--;
1520 state.CurrentDecodeBits = (state.CurrentDecodeBits << 6) | (b2 & 0x3F);
1521 if (
state.AdditionalBytesExpected == 1 &&
state.CurrentDecodeBits >= 864 &&
state.CurrentDecodeBits <= 895)
1522 {
1523 return false;
1524 }
1525 if (
state.AdditionalBytesExpected == 2 &&
state.CurrentDecodeBits >= 272)
1526 {
1527 return false;
1528 }
1529 }
1530 if (
state.AdditionalBytesExpected == 0)
1531 {
1532 state.SequenceInProgress = false;
1533 if (
state.CurrentDecodeBits <
state.ExpectedValueMin)
1534 {
1535 return false;
1536 }
1537 }
1538 }
1539 if (endOfMessage &&
state.SequenceInProgress)
1540 {
1541 return false;
1542 }
1543 return true;
1544 }