package libsignal /* #include */ import "C" import ( "runtime" "unsafe" ) // Address identifies a Signal Protocol session peer: a logical recipient // name (for OMEMO, a bare JID) plus a numeric device ID. type Address struct { Name string DeviceID uint32 } // withCAddress converts addr to a C signal_protocol_address and invokes fn // with a pointer to it. The pointer - and the memory its name field borrows // from addr.Name - is only valid for the duration of fn; it must not be // retained past fn's return. func withCAddress(addr Address, fn func(*C.signal_protocol_address)) { nameBytes := []byte(addr.Name) var namePtr *C.char if len(nameBytes) > 0 { namePtr = (*C.char)(unsafe.Pointer(&nameBytes[0])) } cAddr := C.signal_protocol_address{ name: namePtr, name_len: C.size_t(len(nameBytes)), device_id: C.int32_t(addr.DeviceID), } fn(&cAddr) runtime.KeepAlive(nameBytes) } // addressFromC copies a C signal_protocol_address into a Go Address. func addressFromC(addr *C.signal_protocol_address) Address { return Address{ Name: C.GoStringN(addr.name, C.int(addr.name_len)), DeviceID: uint32(addr.device_id), } }