writeString method

int writeString(
  1. String value, {
  2. bool asciiOptimization = false,
})

Write the given string value and return its offset.

Dart strings are UTF-16 but must be stored as UTF-8 in FlatBuffers. If the given string consists only of ASCII characters, you can indicate enable asciiOptimization. In this mode, writeString() first tries to copy the ASCII string directly to the output buffer and if that fails (because there are no-ASCII characters in the string) it falls back and to the default UTF-16 -> UTF-8 conversion (with slight performance penalty).

Implementation

int writeString(String value, {bool asciiOptimization = false}) {
  assert(!_inVTable);
  if (_strings != null) {
    return _strings!
        .putIfAbsent(value, () => _writeString(value, asciiOptimization));
  } else {
    return _writeString(value, asciiOptimization);
  }
}