-
Type:
New Feature
-
Resolution: Won't Fix
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The current Binary type contract is to pass in a byte array that represents exactly the data to be saved. It would be nice to be able to express a slice/window of a byte array by also accepting offset and length inputs that are used to calculate the relevant portion of the byte array. This is obviously a performance optimization to help avoid copies in performance sensitive parts of a system.
Justification:
In streaming interfaces it is generally not known how big a binary payload will be. Thus something like a `ByteArrayOutputStream` is used, and even when an implementation provides direct access to the underlying buffer, it's not possible[1] to construct a specially sized byte array for the Binary type without a copy.
[1] I'm totally unfamiliar if java offers a way to unsafely trim a byte array, so my claim is speculation.