fromFlexBuffer function

dynamic fromFlexBuffer(
  1. BufferContext buffer,
  2. int offset,
  3. int field, {
  4. bool skipNullCollectionValues = false,
})

Reads the given field as a FlexBuffer and converts it to any Dart value.

Returns null if no data is stored for this field. The returned value can be null, bool, int, double, String, List<dynamic>, Map<String, dynamic>, or nested combinations of these.

If skipNullCollectionValues, if a vector element is null or a map value is null the list element or map entry is not returned. This can be used to allow casting the return value of this method to List with non-null elements (like List<Object>) and Map with non-null values (like Map<String, Object>).

Implementation

@pragma('vm:prefer-inline')
dynamic fromFlexBuffer(BufferContext buffer, int offset, int field,
    {bool skipNullCollectionValues = false}) {
  // Note: Uint8ListReader returns a Uint8List? cast to List<int>, so just cast
  // it back (if that ever changes, add a custom reader)
  final bytes = const Uint8ListReader(lazy: false)
      .vTableGetNullable(buffer, offset, field) as Uint8List?;
  if (bytes == null) return null;
  final ref = flex.Reference.fromBuffer(bytes.buffer);
  return _convertReference(ref, skipNullCollectionValues);
}