[CSHARP-1117] Add a few methods to IBsonStream and make it a fully functional stream Created: 20/Nov/14  Updated: 02/Apr/15  Resolved: 09/Mar/15

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 2.0

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We currently have an IBsonStream interface that has specialized method to read and write BSON primitive data types. If we added just a few methods to it (Read, ReadByte, Write, WriteBytes, etc...) it could act as a fully functional stream.

Our I/O methods are built upon a stream, and if it so happens that the stream we are provided implements IBsonStream, then we use the more efficiently implemented methods from IBsonStream, otherwise we fall back on using the provided stream's Read and Write methods (which requires us to allocate some short lived byte arrays).

If IBsonStream were a fully functional stream (where fully functional is defined as what we need), then internally we could work only with an IBsonStream.

We would end up with probably two implementations of IBsonStream:

1. BsonStream (wraps a standard Stream and implements IBsonStream on top of it)
2. SegmentedBufferStream (analogous to MemoryStream, but implemented on top of an ISegmentedBuffer)

The first would allow us to work with any Stream at all, with some additional overhead because of the need to create intermediate byte arrays when reading and writing some BSON primitives.

The second would be efficiently implemented on top of an ISegmentedBuffer in a way that reduces allocation of temporary byte arrays, thus reducing GC pressure.

The benefit internally is that we would only have to check in one place whether a Stream passed in to us implements IBsonStream or not. If it does, good, otherwise we wrap it in a BsonStream (which implemens IBsonStream). This eliminates multiple checks for whether the interface is implemented and will likely reduce the levels of indirection as well.

This would also allow us to get rid of the current BsonStreamReader and BsonStreamWriter classes, since the functionality they currently provide is already provided by IBsonStream.



 Comments   
Comment by Githook User [ 12/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Fix issue in ByteBufferSlice AccessBackingBytes when slice spans multiple chunks.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/94e7a215194210b475f1e7fcf063b10f1e79ad8a

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Rename MaxPoolSize to MaxChunkCount in BsonChunkPool.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/00d67cdd9155be71ffd829df51013a27db0b17c6

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Minor changes preparing for code review.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f7ee6f262d71b1e27f09b3e2ab3a0bc342843cbc

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for MultiChunkBuffer.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/01f1f5ba1d008684cc19b414c879bbe205f90122

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for SingleChunkBuffer.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/7527f16e1436b6643c5b0da67133e3f77c66b4c2

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Moved PowerOf2 calls from Shared folder to Bson folder.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/664b2c65c296821be879b3614fa15e67398ff681

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added unit tests for PowerOf2.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a80d201c088b995156b1ec9d718565437420dc47

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Add tests for StreamExtensionMethods.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d688e21a16018027205d730050d967a1115332e1

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for ByteBufferFactory.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c32ace915448408e50527230139484aeff82c3f2

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for ByteArrayBuffer.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3ab1fe0a7c23c823a265239603fa4f3d053ef0b8

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for ByteBufferStream.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/8c10a8da4371e1914851bc47375a3a63fbfcb86f

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for BsonChunkPool.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/1d54589a5627d05275971722a1928eda30be84e5

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for OutputBufferChunkSource.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/9649ad70176b43560f214cc0e4d74cbb3c5c70c5

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for InputBufferChunkSource.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/24ff078051cfd273268f033fdb46f1e1554bb04f

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Add tests for ByteBufferSlice.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5d963f07ee414c2bf0772cdf2d6cb386c37d9b70

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Add tests for ByteArrayChunk.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/8eac984a187cc66d10e7fda33e7ec2cfefddea1e

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Add tests for BsonStreamExtensions.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f7ab79acc003facc2b97871a79126b0e06030bc6

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Added tests for BsonStreamAdapter.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ca3286e9e77b0bfbcea2408da091c163c1ba00af

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1117: Replace IBsonStream interface with a BsonStream abstract class.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/370dee9616a8be2f0709b41483b9dbc56c4aff36

Comment by Githook User [ 09/Mar/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1112 and CSHARP-1117: Simplify IByteBuffer and enhance IBsonStream.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/068438c60f091c9412e85870e80813b5a755c8f5

Generated at Wed Feb 07 21:38:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.