//export swift_io_v_v23_security_simple_nativeSetBlessings func swift_io_v_v23_security_simple_nativeSetBlessings(ctxHandle C.GoContextHandle, encodedSwiftBlessings C.SwiftByteArray, errOut *C.SwiftVError) { ctx := context.GoContext(uint64(ctxHandle)) encodedBlessings := util.GoBytesNoCopy(unsafe.Pointer(&encodedSwiftBlessings)) var blessings security.Blessings if err := vom.Decode(encodedBlessings, &blessings); err != nil { ctx.Error("Unable to decode:", err) util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut)) return } principal := v23.GetPrincipal(ctx) if err := principal.BlessingStore().SetDefault(blessings); err != nil { util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut)) return } }
// Exports the discovery advertise API to CGO using JSON to marshal ads //export swift_io_v_v23_discovery_advertise func swift_io_v_v23_discovery_advertise(ctxHandle C.GoContextHandle, discoveryHandle C.GoDiscoveryHandle, adJson C.SwiftByteArray, visibilityArray C.SwiftCStringArray, asyncId C.AsyncCallbackIdentifier, doneCallback C.SwiftAsyncSuccessCallback, errOut *C.SwiftVError) bool { ctx := scontext.GoContext(uint64(ctxHandle)) d := GoDiscoveryT(uint64(discoveryHandle)) ad := discovery.Advertisement{} if err := json.Unmarshal(sutil.GoBytesNoCopy(unsafe.Pointer(&adJson)), &ad); err != nil { sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut)) return false } var visibility []security.BlessingPattern for _, v := range visibilityArray.toStrings() { visibility = append(visibility, security.BlessingPattern(v)) } doneChan, err := d.Advertise(ctx, &ad, visibility) if err != nil { sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut)) return false } go func() { <-doneChan C.CallAdvertisingCallback(doneCallback, asyncId) }() return true }