[GODRIVER-474] Expose Cursor.Peek() function to know how much space a document will require Created: 20/Jun/18 Updated: 10/Sep/18 Resolved: 10/Sep/18 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Gregoire Pean | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
It would be convenient to expose a Peek function for Cursor, so that, if one is interested in allocating a byte slice to accommodate the Decode(), they can do it. Otherwise, we have to guess-timate the size of the byte slice to pass to Decode, or look for NewErrTooSmall errors, which is not optimal. relevant code: https://github.com/mongodb/mongo-go-driver/blob/2bc72ab2a7bf23f6f53554e9cf48b061943d664e/bson/decode.go#L181-L197 |
| Comments |
| Comment by Kristofer Brandow (Inactive) [ 10/Sep/18 ] |
|
Hi gpean, Since we're going to add support for appending the document to a slice of bytes via Thanks, Kris |
| Comment by Gregoire Pean [ 21/Jun/18 ] |
|
Hi Kris, Here I'm really looking to stream the whole binary/bson response as the HTTP response, so that the browser can consume it directly, and so that we avoid unnecessary conversions. In addition to reworking and/or documenting the DecodeBytes, do you think you could add support for getting (more importantly, streaming) the whole array of documents as BSON? Thanks |
| Comment by Kristofer Brandow (Inactive) [ 21/Jun/18 ] |
|
Hi gpean, I was going to ask about the DecodeBytes function. I think we still need to document it, but the bytes from DecodeBytes should be copied, since they are the bytes we received from the server, so keeping it around could potentially keep a large slice of memory allocated. --Kris |
| Comment by Gregoire Pean [ 21/Jun/18 ] |
|
Nevermind, I think what I'm asking does not make sense / is unneeded given there is DecodeBytes() available |
| Comment by Gregoire Pean [ 21/Jun/18 ] |
|
By Peek() I really meant PeakLength() |