|
1 2 3 4 5 6 |
static Pointer<Uint8> generateUint8ListPointer(Uint8List types) { final blob = calloc<Uint8>(types.length); final blobBytes = blob.asTypedList(types.length); blobBytes.setAll(0, types); return blob; } |
日期: 2025年12月13日
Flutter Uint8List to Pointer
‘withUnsafeBytes’ is deprecated: use ‘withUnsafeBytes(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R’ instead
在编写 Swift 代码的时候,执行如下代码的时候:
|
1 2 3 4 5 |
var pbCert = Data() let err = pbCert.withUnsafeBytes { buffer in let pulSize: CUnsignedInt = pbCert.count return doSomeThings(buffer, pulSize) } |
出现如下警告:
|
1 |
‘withUnsafeBytes’ is deprecated: use `withUnsafeBytes(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead |
修正警告的方式,参考使用如下代码:
|
1 2 3 4 5 6 |
var pbCert = Data() let err = pbCert.withUnsafeBytes { buffer in let byteBuffer = buffer.bindMemory(to: UInt8.self) let pulSize: CUnsignedInt = CUnsignedInt(byteBuffer.count) return doSomeThings(byteBuffer.baseAddress!, pulSize) } |