function makeBufferViews(subtreeDescription, subtreeJson) {
  // Content availability is optional.
  const hasContent = defined(subtreeDescription.contentAvailability);

  // pass 1: parse availability -------------------------------------------
  const parsedAvailability = {
    tileAvailability: parseAvailability(subtreeDescription.tileAvailability),
    childSubtreeAvailability: parseAvailability(
      subtreeDescription.childSubtreeAvailability,
    ),
  };

  if (hasContent) {
    parsedAvailability.contentAvailability =
      subtreeDescription.contentAvailability.map(parseAvailability);
  }

  // to simulate additional buffer views for metadata or other purposes.
  if (defined(subtreeDescription.other)) {
    parsedAvailability.other = parseAvailability(subtreeDescription.other);
  }

  // pass 2: create buffer view JSON and gather typed arrays ------------------
  const bufferViewsU8 = {
    internal: [],
    external: [],
    count: 0,
  };

  const useLegacySchema = subtreeDescription.useLegacySchema ?? false;
  const bufferViewJsonArray = [];
  gatherBufferViews(
    bufferViewsU8,
    bufferViewJsonArray,
    parsedAvailability.tileAvailability,
    useLegacySchema,
  );

  if (hasContent) {
    parsedAvailability.contentAvailability.forEach(
      function (contentAvailability) {
        gatherBufferViews(
          bufferViewsU8,
          bufferViewJsonArray,
          contentAvailability,
          useLegacySchema,
        );
      },
    );
  }
  gatherBufferViews(
    bufferViewsU8,
    bufferViewJsonArray,
    parsedAvailability.childSubtreeAvailability,
    useLegacySchema,
  );

  // to simulate additional buffer views for metadata or other purposes.
  if (defined(parsedAvailability.other)) {
    gatherBufferViews(
      bufferViewsU8,
      bufferViewJsonArray,
      parsedAvailability.other,
      useLegacySchema,
    );
  }
  if (bufferViewJsonArray.length > 0) {
    subtreeJson.bufferViews = bufferViewJsonArray;
  }

  // pass 3: update the subtree availability JSON -----------------------------
  subtreeJson.tileAvailability =
    parsedAvailability.tileAvailability.availabilityJson;
  subtreeJson.childSubtreeAvailability =
    parsedAvailability.childSubtreeAvailability.availabilityJson;

  if (hasContent) {
    const contentAvailabilityArray = parsedAvailability.contentAvailability;
    if (useLegacySchema) {
      subtreeJson.extensions = {
        "3DTILES_multiple_contents": {
          contentAvailability: contentAvailabilityArray.map(function (x) {
            return x.availabilityJson;
          }),
        },
      };
    } else if (contentAvailabilityArray.length > 1) {
      subtreeJson.contentAvailability = contentAvailabilityArray.map(
        function (x) {
          return x.availabilityJson;
        },
      );
    } else {
      subtreeJson.contentAvailability =
        contentAvailabilityArray[0].availabilityJson;
    }
  }

  // pass 4: add metadata buffer views --------------------------------------
  const metadata = subtreeDescription.metadata;
  if (defined(metadata)) {
    addMetadata(bufferViewsU8, subtreeJson, metadata, useLegacySchema);
  }

  // wrap up ----------------------------------------------------------------

  return bufferViewsU8;
}
Generate a subtree buffer
@param {SubtreeDescription} subtreeDescription A JSON description of the subtree's structure and values
@param {boolean} constantOnly true if all the bitstreams are constant, i.e. no buffers/bufferViews are needed.
@return {GeneratedSubtree} The procedurally generated subtree and an external buffer.

@example
 const subtreeDescription = {
   tileAvailability: {
     descriptor: 1,
     lengthBits: 5,
     isInternal: true,
   },
   contentAvailability: {
     descriptor: "11000",
     lengthBits: 5,
     isInternal: true,
   },
   childSubtreeAvailability: {
     descriptor: "1111000010100000",
     lengthBits: 16,
     isInternal: true,
   },
   other: {
     descriptor: "101010",
     lengthBits: 6,
     isInternal: false,
   },
 };
 const results = ImplicitTilingTester.generateSubtreeBuffers(
   subtreeDescription
 );

@private