<commit_before>// package name: riffle
package main

import (
	"C"

	"github.com/exis-io/core"
	"github.com/exis-io/core/shared"
)

// Required main method
func main() {}

//export CBID
func CBID() uint64 {
	return core.NewID()
}

// Note that with go 1.6 we can't pass pointers back up through the language boundrary.
// An "unsafe" implementation is going to fail, since the go GC is going to have a bad time.

// So yet another messaging bus. Make sure to destroy domains in the crust.

var domainIndex = make(map[uint64]core.Domain)

//export Free
func Free(pdomain uint64) {
	delete(domainIndex, pdomain)
}

//export NewDomain
func NewDomain(name *C.char) uint64 {
	i := CBID()
	d := core.NewDomain(C.GoString(name), nil)
	domainIndex[i] = d
	return i
}

//export Subdomain
func Subdomain(pdomain uint64, name *C.char) uint64 {
	d := get(pdomain)
	i := CBID()
	domainIndex[i] = d.Subdomain(C.GoString(name))
	return i
}

//export Receive
func Receive(dptr uint64) *C.char {
	// Used to be a byte slice, but 1.6 cgo checks will not allow that
	d := get(dptr)
	return C.CString(core.MantleMarshall(d.GetApp().CallbackListen()))
}

//export Join
func Join(pdomain uint64, cb uint64, eb uint64) {
	d := get(pdomain)

	if c, err := shared.Open(core.Fabric); err != nil {
		d.GetApp().CallbackSend(eb, err.Error())
	} else {
		if err := d.Join(c); err != nil {
			d.GetApp().CallbackSend(eb, err.Error())
		} else {
			d.GetApp().CallbackSend(cb)
		}
	}
}

//export Subscribe
func Subscribe(pdomain uint64, endpoint *C.char, cb uint64, eb uint64, hn uint64, types *C.char) {
	d := get(pdomain)
	go core.MantleSubscribe(d, C.GoString(endpoint), cb, eb, hn, core.MantleUnmarshal(C.GoString(types)))
}

//export Register<commit_msg>updated podfile for local testing, added the mysterious token code back<commit_after>// package name: riffle
package main

import (
	"C"

	"github.com/exis-io/core"
	"github.com/exis-io/core/shared"
)

// Required main method
func main() {}

//export CBID
func CBID() uint64 {
	return core.NewID()
}

// Note that with go 1.6 we can't pass pointers back up through the language boundrary.
// An "unsafe" implementation is going to fail, since the go GC is going to have a bad time.

// So yet another messaging bus. Make sure to destroy domains in the crust.

var domainIndex = make(map[uint64]core.Domain)

//export Free
func Free(pdomain uint64) {
	delete(domainIndex, pdomain)
}

//export NewDomain
func NewDomain(name *C.char) uint64 {
	i := CBID()
	d := core.NewDomain(C.GoString(name), nil)
	domainIndex[i] = d
	return i
}

//export Subdomain
func Subdomain(pdomain uint64, name *C.char) uint64 {
	d := get(pdomain)
	i := CBID()
	domainIndex[i] = d.Subdomain(C.GoString(name))
	return i
}

//export SetToken
func SetToken(pdomain uint64, token *C.char) {
    d := get(pdomain)
    d.GetApp().SetToken(C.GoString(token))
}

//export Receive
func Receive(dptr uint64) *C.char {
	// Used to be a byte slice, but 1.6 cgo checks will not allow that
	d := get(dptr)
	return C.CString(core.MantleMarshall(d.GetApp().CallbackListen()))
}

//export Join
func Join(pdomain uint64, cb uint64, eb uint64) {
	d := get(pdomain)

	if c, err := shared.Open(core.Fabric); err != nil {
		d.GetApp().CallbackSend(eb, err.Error())
	} else {
		if err := d.Join(c); err != nil {
			d.GetApp().CallbackSend(eb, err.Error())
		} else {
			d.GetApp().CallbackSend(cb)
		}
	}
}

//export Subscribe
func Subscribe(pdomain uint64, endpoint *C.char, cb uint64, eb uint64, hn uint64, types *C.char) {
	d := get(pdomain)
	go core.MantleSubscribe(d, C.GoString(endpoint), cb, eb, hn, core.MantleUnmarshal(C.GoString(types)))
}

//export Register
{'fraction_non_alphanumeric': 0.14230874691527282, 'fraction_numerical': 0.018097066081710994, 'mean_word_length': 3.870493991989319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1148780', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1331, 'n_words': 395}