lookup method

  1. @override
String lookup(
  1. ByteData byteData,
  2. StringEncoding encoding,
  3. StringLocation location,
  4. Object? relatedKey,
)
override

Use the specified {@code byteBuffer} and its {@code encoding} to find a string in the string table, if it exists, return its reference, if not, constructs a new one.

If the string to be lookup is located in StringLocation.eVoid, this means that the string will not be used, can simply return an empty string.

The byte buffer used to lookup The StringEncoding of a supported encoding The location of the string If the string located in the value position of the k-v structure

Return The string corresponding to ByteData

Implementation

@override
String lookup(
  ByteData byteData,
  StringEncoding encoding,
  StringLocation location,
  Object? relatedKey,
) {
  if (location == StringLocation.eVoid) {
    return "";
  }

  var dataList = byteData.buffer.asUint8List();
  if (encoding == StringEncoding.latin) {
    // iso-8896-1标准
    return const Latin1Codec().decode(dataList);
  } else if (encoding == StringEncoding.utf16Le) {
    // utf16-le标准
    var decoder = utf16.decoder as Utf16Decoder;
    return decoder.decodeUtf16Le(dataList);
  } else {
    return const Utf8Codec().decode(dataList);
  }
}