Rework the BSON hierarchy?

Currently, we have:

  • Bson: a stored BSON document
  • BsonArray: a stored BSON array
  • BsonValueWriter: a writer for the context of values (typically: array items)
  • BsonFieldWriter: a write for the context of fields (typically: document fields)
  • BsonDocumentReader: a reader for a BSON document
  • BsonArrayReader: a reader for a BSON array
  • BsonValueReader: a reader for an arbitrary BSON value

As the number of classes grow, knowing which types should be used in which situation becomes more difficult (compare that with the official driver, which has BsonDocument, Document, etc).

A possible rename is as follows:

  • BsonDocumentReaderBsonDocument
  • BsonArrayReaderBsonArray
  • BsonValueReaderBsonValue
  • BsonImmutableBsonDocument, which would implement BsonDocument
  • BsonArrayImmutableBsonArray, which would implement BsonArray
  • BsonValueWriter (unchanged)
  • BsonFieldWriter (unchanged)

⚠️ This is a major breaking change for bson (most notably, BsonArray changes meaning).

Another side effect is that this would encourage users to use the readers in most situations, instead of using the stored types. This may result in improved performance. One downside is that currently, we can control the APIs of Bson and BsonValueWriter, but they would become merged.