示例#1
0
文件: codec.go 项目: haiger/beansdb
func DCEncode(s string) string {
	cs := C.CString(s)
	defer C.free(unsafe.Pointer(cs))

	buf := C.malloc(255)
	defer C.free(buf)
	n := C.dc_encode((*_Ctype_char)(buf), cs, (_Ctype_int)(len(s)))
	if n > 0 {
		return C.GoStringN((*_Ctype_char)(buf), n)
	}
	return s
}
示例#2
0
文件: codec.go 项目: Mrhjx2/beansdb
func (dc *Codec) Encode(src string) (dst string, idx int) {
	var cdc *C.Codec = dc.cdc
	n := C.dc_encode(cdc, dc.buf, BUFSIZE, C.CString(src), C.int(len(src)))
	return C.GoStringN(dc.buf, n), 1
}