function readAndAssertType(bufferReader, expectedType, name) {
  const start = bufferReader.index;
  const { value, type } = readTypeAndMaybeValue(bufferReader, name);
  if (type !== expectedType) {
    throw Error(`Unexpected type ${quote(type)} at index ${start} of ${name}`);
  }
  return value;
}
@param {BufferReader} bufferReader
@param {'boolean' | 'integer' | 'float64' | 'string' | 'selector' | 'bytestring'} expectedType
@param {string} name
@returns {any}