Instance Method
copyToUnsafeMutableBytes(of:)
Copies up to MemoryLayout<T>.size bytes from this Data into the raw memory of value, used to populate opaque C structs such as secp256k1_pubkey and secp256k1_musig_aggnonce.
func copyToUnsafeMutableBytes<T>(of value: inout T)
Parameters
-
value
-
The inout value whose raw bytes are overwritten; only the leading min(self.count, MemoryLayout<T>.size) bytes are written.
Discussion
Swift-side helper for round-tripping opaque upstream structs through wire formats. The upstream C structs are declared as unsigned char data[N] arrays, so copying their raw bytes into a freshly-zeroed T via this helper is safe when the Swift Data was produced by a matching upstream *_serialize call on the same version of libsecp256k1.
Important
These struct layouts are not stable across libsecp256k1 versions. Cross-process persistence should use the upstream *_serialize / *_parse functions exposed by the wrapper types, not the raw struct bytes.