在Android中,我可以按照以下代码将对象转换为ByteArray,然后将其编码为Base64(URL_SAFE)
val myByteArrayObject = protobufObject.toByteArray()
val meEncodedObject = android.util.Base64.encodeToString.encodeToString(
myByteArrayObject, android.util.Base64.DEFAULT).trim()
如何在Swift中实现呢?
答案 0 :(得分:0)
找到答案。
do {
let protobufSerialized = try protobufObject.serializedData()
let protobufEncoded = protobufSerialized.base64EncodedString()
// Do whatever need to be done with the protobufEncoded
} catch { }
很难找到的主要隐藏函数是serializedData()
上存在的SwiftProtobuf.Message