(
ReadContext context,
MetaStringDecoder decoder,
IReadOnlyList<MetaStringEncoding> encodings)
| 1595 | } |
| 1596 | |
| 1597 | private static MetaString ReadMetaString( |
| 1598 | ReadContext context, |
| 1599 | MetaStringDecoder decoder, |
| 1600 | IReadOnlyList<MetaStringEncoding> encodings) |
| 1601 | { |
| 1602 | uint header = context.Reader.ReadVarUInt32(); |
| 1603 | int length = checked((int)(header >> 1)); |
| 1604 | bool isRef = (header & 1) == 1; |
| 1605 | if (isRef) |
| 1606 | { |
| 1607 | int index = length - 1; |
| 1608 | MetaString? cached = context.GetReadMetaString(index); |
| 1609 | if (cached is null) |
| 1610 | { |
| 1611 | throw new InvalidDataException($"unknown meta string ref index {index}"); |
| 1612 | } |
| 1613 | |
| 1614 | return cached.Value; |
| 1615 | } |
| 1616 | |
| 1617 | MetaString value; |
| 1618 | if (length == 0) |
| 1619 | { |
| 1620 | value = MetaString.Empty(decoder.SpecialChar1, decoder.SpecialChar2); |
| 1621 | } |
| 1622 | else |
| 1623 | { |
| 1624 | MetaStringEncoding encoding; |
| 1625 | if (length > 16) |
| 1626 | { |
| 1627 | long hash = context.Reader.ReadInt64(); |
| 1628 | byte rawEncoding = unchecked((byte)(hash & 0xFF)); |
| 1629 | encoding = (MetaStringEncoding)rawEncoding; |
| 1630 | } |
| 1631 | else |
| 1632 | { |
| 1633 | encoding = (MetaStringEncoding)context.Reader.ReadUInt8(); |
| 1634 | } |
| 1635 | |
| 1636 | if (!encodings.Contains(encoding)) |
| 1637 | { |
| 1638 | throw new InvalidDataException($"meta string encoding {encoding} not allowed in this context"); |
| 1639 | } |
| 1640 | |
| 1641 | byte[] bytes = context.Reader.ReadBytes(length); |
| 1642 | value = decoder.Decode(bytes, encoding); |
| 1643 | } |
| 1644 | |
| 1645 | context.AppendReadMetaString(value); |
| 1646 | return value; |
| 1647 | } |
| 1648 | |
| 1649 | private static ulong MetaStringHash(MetaString metaString) |
| 1650 | { |
nothing calls this directly
no test coverage detected