func Unmarshal(bytes []byte, i interface{}) *McpackError { buf := unsafe.Pointer(&bytes[0]) tmpsize := len(bytes) * 3 tmpbuf := C.malloc(C.size_t(tmpsize)) defer C.free(tmpbuf) pack := C.mc_pack_open_r((*C.char)(buf), C.int(len(bytes)), (*C.char)(tmpbuf), C.int(tmpsize)) defer C.mc_pack_close(pack) if err := unmarshal(pack, i); err != nil { return err } return nil }
func Marshal(i interface{}) ([]byte, *McpackError) { buf := C.malloc(PACK_DEFAULT_SIZE) defer C.free(buf) tmpbuf := C.malloc(PACK_TMP_BUFSIZE) defer C.free(tmpbuf) pack := C.mc_pack_open_w(C.int(2), (*C.char)(buf), PACK_DEFAULT_SIZE, (*C.char)(tmpbuf), PACK_TMP_BUFSIZE) defer C.mc_pack_close(pack) if err := marshal(pack, reflect.ValueOf(i)); err != nil { return nil, err } packet := C.GoBytes(buf, C.mc_pack_get_size(pack)) return packet, nil }