fromBuffer static method

Reference fromBuffer(
  1. ByteBuffer buffer
)

Use this method to access the root value of a FlexBuffer.

Implementation

static Reference fromBuffer(ByteBuffer buffer) {
  final len = buffer.lengthInBytes;
  if (len < 3) {
    throw UnsupportedError('Buffer needs to be bigger than 3');
  }
  final byteData = ByteData.view(buffer);
  final byteWidth = byteData.getUint8(len - 1);
  final packedType = byteData.getUint8(len - 2);
  final offset = len - byteWidth - 2;
  return Reference._(ByteData.view(buffer), offset,
      BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
}