Copying data out of Cord - CopyToArray/pread/memcpy like interface?
Cord has CopyCordToString(). Could there be a helper function to copy to a char* buffer? For example,
// Copies the data in the cord from |offset| up to buffer |size|. Returns the actual number of bytes copied.
// Returns 0 if offset is out of bound.
size_t CopyToArray(char* buffer, size_t size, size_t offset = 0);
Alternatives considered: use cord.Subcord(offset, size) and iterate chunks, but Subcord() seems to have the overhead of creating new cord reps.
Can you tell us more about your use case?
I'm using grpc to fetch some data. Since open source protobuf copies data, I didn't parse the response into protobuf. I convert grpc response data slices into a cord and plan to operate on the cord.
To be honest this sounds like premature optimization. Are you sure the overhead of Subcord matters for this use case?
However, I'd bet protobuf and/or grpc are currently working on getting a better zero-copy implementation in place now that Cord has been open source for some time. You might consider asking them for what you need.