Skip to content
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

[SR-9720] Foundation Data API: add Data.copyBytes methods taking UnsafeRawBufferPointer. #3553

Closed
atrick opened this issue Jan 21, 2019 · 3 comments

Comments

@atrick
Copy link
Member

atrick commented Jan 21, 2019

Previous ID SR-9720
Radar rdar://47431395
Original Reporter @atrick
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels New Feature
Assignee @phausler
Priority Medium

md5: a31620f897c965b5529b6d73aec1ee7c

cloned from:

  • SR-5363 Update Foundation.Data API for UnsafeRawBufferPointer.

relates to:

  • SR-9719 Foundation Data API: add copyBytes methods taking UnsafeMutableRawPointer

Issue Description:

In the Foundation Data API, add methods that copy into a raw buffer pointer:

public func copyBytes(to buffer: UnsafeMutableRawBufferPointer, from range: Range<Index>? = nil) -> Int
public func copyBytes(to buffer: UnsafeMutableRawBufferPointer, count: Int)

The raw buffer form is more general than this typed API:

public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: Range<Index>? = nil) -> Int

However, we don't yet have language support for automatic typed-to-raw buffer argument conversion, so the typed buffer API is still a useful convenience.

The behavior of the API that takes a `count` instead of a `range` should behave the same as this existing API, except that it will be bounds checked in Debug builds:

public func copyBytes(to buffer: UnsafeMutablePointer<UInt8>, count: Int)

These overloads should be completely source compatible, but I have not verified with a prototype.

@belkadan
Copy link

Same comments as SR-9719.

@atrick
Copy link
Member Author

atrick commented Jan 23, 2019

SR-9719 comments are correct, but to be clear we're not proposing that anything be deprecated here.

I don't know if we'll ever decide to automate the UnsafeBufferPointer<T> to UnsafeRawBufferPointer argument conversion.

@atrick
Copy link
Member Author

atrick commented May 26, 2019

Implemented in `DataProtocol` in Swift 5. Hurray!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants