gpt4 book ai didi

android - 如何在 Swift 中将 protobuf 对象转换为 ByteArray 并使用 Base64 URL_SAFE 进行编码?

转载 作者:行者123 更新时间:2023-11-29 05:35:33 25 4
gpt4 key购买 nike

在 Android 中,我可以将对象转换为 ByteArray,然后按照下面的代码将其编码为 Base64 (URL_SAFE)

    val myByteArrayObject = protobufObject.toByteArray()
val meEncodedObject = android.util.Base64.encodeToString.encodeToString(
myByteArrayObject, android.util.Base64.DEFAULT).trim()

如何在 Swift 中实现这一目标?

最佳答案

找到了答案。

do {
let protobufSerialized = try protobufObject.serializedData()
let protobufEncoded = protobufSerialized.base64EncodedString()

// Do whatever need to be done with the protobufEncoded
} catch { }

很难找到的主要隐藏函数是 serializedData() ,它存在于 SwiftProtobuf.Message

关于android - 如何在 Swift 中将 protobuf 对象转换为 ByteArray 并使用 Base64 URL_SAFE 进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57068823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com