[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:
Related
is related to GODRIVER-475 Add to Cursor a way to append documen... Closed

 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 GODRIVER-475. We feel like this is a more robust solution than attempting to providing the raw bytes returned from the server.

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()

Generated at Thu Feb 08 08:34:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.