Closed dongfanger2018 closed 1 week ago
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?
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
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 useserializedData()
to get the bytes as an instance ofData
where required.
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()