A have a structure like this (defined in bson.h of mongodb c driver):
typedef struct
{
uint32_t domain;
uint32_t code;
char message[504];
} bson_error_
Quick hack to retrieve message String
from bson_error_t
:
extension bson_error_t {
mutating func messageString() -> String? {
return String.fromCString(
{ (p:UnsafePointer) in UnsafePointer(p) }(&self.message.0)
)
}
}
// Usage:
var err: UnsafeMutablePointer = ...
...
let errMessage = err.memory.messageString()