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

error in readme #1692

Closed
dongfanger2018 opened this issue Aug 15, 2024 · 4 comments
Closed

error in readme #1692

dongfanger2018 opened this issue Aug 15, 2024 · 4 comments

Comments

@dongfanger2018
Copy link

Before opening a new issue, please double check the past issues (both open and
closed ones) to see if your problem has been discussed before and already
contains an answer/solution. Likewise, check the FAQ in the Documentation folder
for some common things -
https://github.com/apple/swift-protobuf/blob/main/Documentation/FAQ.md

Please be sure to include:

  • what OS you are developing on (Linux or macOS, including the version)

  • macOS

  • for macOS, what version of Xcode you are using (xcodebuild -version),
    for Linux, what version of Swift (swift --version)

  • what version of Swift is your code set to compile with (i.e. from project
    settings, etc.)

  • what branch/tag of SwiftProtobuf you are using (1.0.0, etc.)
    *main

  • if you are getting compile errors, please be sure include all errors/warnings,
    sometimes the error before the one you are stuck on is important.

  • lastly, if it all possible, provide a snippet of .proto and/or source
    that shows the problem.

Thank you!

// Serialize to binary protobuf format: you can choose to serialize into
// any type conforming to SwiftProtobufContiguousBytes. For example:
let binaryData: Data = try info.serializedBytes()
let binaryDataAsBytes: [UInt8] = try info.serializedBytes()

should it be?
let binaryData: Data = try info.serializedData()

@thomasvl
Copy link
Collaborator

serializedData still exists for compatibility, but the other apis are the preferred path forward.

@FranzBusch @gjcairo – Did you want to update the comments to reflect this? I guess all the parsing apis got annotated as deprecated, but not the serialization apis?

@FranzBusch
Copy link
Member

IMO the docs are just wrong here serializedData should not be deprecated since it is totally fine to use and just a convenience overload at this point. cc @gjcairo

@gjcairo
Copy link
Contributor

gjcairo commented Sep 2, 2024

Apologies, I'd missed this issue.

I don't think the docs are wrong here. serializedBytes() is generic and returns some SwiftProtobufContiguousBytes.

  • let binaryData: Data = try info.serializedBytes() will resolve the return type to Data
  • let binaryDataAsBytes: [UInt8] = try info.serializedBytes() will resolve it to [UInt8]
    Both Data and [UInt8] conform to SwiftProtobufContiguousBytes.

serializedData() hasn't been deprecated and can still be used, but I don't think this particular bit of the docs should be changed.

However if you think it's worth mentioning, I can add something like:

Note that while the serializedBytes() spelling is generally preferred, you may also use serializedData() to get the bytes as an instance of Data where required.

@gjcairo
Copy link
Contributor

gjcairo commented Sep 3, 2024

#1710

@thomasvl thomasvl closed this as completed Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants