addString method

void addString(
  1. String value
)

Adds a string value.

Implementation

void addString(String value) {
  _integrityCheckOnValueAddition();
  if (_stringCache.containsKey(value)) {
    _stack.add(_stringCache[value]!);
    return;
  }
  final utf8String = utf8.encode(value);
  final length = utf8String.length;
  final bitWidth = BitWidthUtil.uwidth(length);
  final byteWidth = _align(bitWidth);
  _writeUInt(length, byteWidth);
  final stringOffset = _offset;
  final newOffset = _newOffset(length + 1);
  _pushBuffer(utf8String);
  _offset = newOffset;
  final stackValue =
      _StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
  _stack.add(stackValue);
  _stringCache[value] = stackValue;
}