-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add zero-copy serialization APIs. #357
base: master
Are you sure you want to change the base?
Changes from 9 commits
05a257e
ed67582
0ab5d35
c30e838
2d174df
42fe380
5696a01
7812651
8da0d7f
e524c53
4040ae7
86c8a73
13629dd
38155e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package tiledb | |
import "C" | ||
import ( | ||
"fmt" | ||
"io" | ||
) | ||
|
||
// BufferList A list of TileDB BufferList objects | ||
|
@@ -44,6 +45,36 @@ func (b *BufferList) Context() *Context { | |
return b.context | ||
} | ||
|
||
// WriteTo writes the contents of a BufferList to an io.Writer. | ||
func (b *BufferList) WriteTo(w io.Writer) (n int64, err error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were the named return values intentional? Feel free to disregard, just pointing it out since I don't see these names being directly used in the function body. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must have been from a previous iteration of the code. Removed. |
||
nbuffs, err := b.NumBuffers() | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
written := int64(0) | ||
|
||
for i := uint(0); i < uint(nbuffs); i++ { | ||
buff, err := b.GetBuffer(i) | ||
if err != nil { | ||
return 0, err | ||
} | ||
n, err := buff.WriteTo(w) | ||
written += n | ||
|
||
buff.Free() | ||
|
||
if err != nil { | ||
return written, err | ||
} | ||
} | ||
|
||
return written, nil | ||
} | ||
|
||
// Static assert that BufferList implements io.WriterTo. | ||
var _ io.WriterTo = (*BufferList)(nil) | ||
|
||
// NumBuffers returns number of buffers in the list. | ||
func (b *BufferList) NumBuffers() (uint64, error) { | ||
var numBuffers C.uint64_t | ||
|
@@ -82,6 +113,8 @@ func (b *BufferList) TotalSize() (uint64, error) { | |
} | ||
|
||
// Flatten copies and concatenates all buffers in the list into a new buffer. | ||
// | ||
// Deprecated: Use WriteTo instead for increased performance. | ||
func (b *BufferList) Flatten() (*Buffer, error) { | ||
buffer := Buffer{context: b.context} | ||
freeOnGC(&buffer) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since
b
is the object that implements this method the keepalive isn't neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. I was being extra cautious, but if we call
b.WriteTo(w)
, it becomes clear thatb
is being kept somewhere reachable.