getStringView method

StringView? getStringView(
  1. int fieldId
)

Returns a zero-copy UTF-8 view of a string field.

Use this instead of getString whenever the value only needs to be compared, hashed or prefix-matched: no String is allocated.

Implementation

StringView? getStringView(int fieldId) {
  final cursor = this.cursor();
  while (cursor.next()) {
    if (cursor.fieldId != fieldId) continue;
    _requireWire(cursor, fieldId, VxsWire.lengthDelimited);
    return StringView(
      buffer,
      cursor.valueOffset,
      cursor.valueOffset + cursor.valueLength,
    );
  }
  return null;
}