<commit_before>package msi

/*
#include <stdlib.h>
#include "call_microservice.h"
*/
import "C"

import (
	"runtime"
	"unsafe"
)

type Param struct {
	ptr      *C.msParam_t
	rodsType string
}

func NewParam(paramType string) *Param {
	p := new(Param)

	p.rodsType = paramType

	cTypeStr := C.CString(paramType)
	defer C.free(unsafe.Pointer(cTypeStr))

	p.ptr = C.NewParam(cTypeStr)

	runtime.SetFinalizer(p, paramDestructor)

	return p
}

func (param *Param) String() string {

	var cString *C.char

	switch param.rodsType {
	case STR_MS_T:
		cString = (*C.char)(param.ptr.inOutStruct)
	default:
		return (param.rodsType + ".String() not supported")
	}

	return C.GoString(cString)
}

func (param *Param) Bytes() []byte {
	var bytes []byte

	if param.rodsType == BUF_LEN_MS_T {

		internalBuff := param.ptr.inpOutBuf

		outBuff := unsafe.Pointer(internalBuff.buf)

		bufLen := int(internalBuff.len)

		bytes = (*[1 << 30]byte)(outBuff)[:bufLen:bufLen]
	}

	return bytes
}

func (param *Param) SetInt(val int) *Param {
	if param.rodsType == INT_MS_T {
		*((*C.int)(param.ptr.inOutStruct)) = C.int(val)
	}
	return param
}

func (param *Param) SetString(val string) *Param {
	if param.rodsType == STR_MS_T {
		param.ptr.inOutStruct = unsafe.Pointer(C.CString(val))
	}
	return param
}

func (param *Param) SetDataObjInp(input map[string]interface{}) *Param {<commit_msg>Implemented Param.SetKVP<commit_after>package msi

/*
#include <stdlib.h>
#include "call_microservice.h"
#include "rcMisc.h"
*/
import "C"

import (
	"runtime"
	"unsafe"
)

type Param struct {
	ptr      *C.msParam_t
	rodsType string
}

func NewParam(paramType string) *Param {
	p := new(Param)

	p.rodsType = paramType

	cTypeStr := C.CString(paramType)
	defer C.free(unsafe.Pointer(cTypeStr))

	p.ptr = C.NewParam(cTypeStr)

	runtime.SetFinalizer(p, paramDestructor)

	return p
}

func (param *Param) String() string {

	var cString *C.char

	switch param.rodsType {
	case STR_MS_T:
		cString = (*C.char)(param.ptr.inOutStruct)
	default:
		return (param.rodsType + ".String() not supported")
	}

	return C.GoString(cString)
}

func (param *Param) Bytes() []byte {
	var bytes []byte

	if param.rodsType == BUF_LEN_MS_T {

		internalBuff := param.ptr.inpOutBuf

		outBuff := unsafe.Pointer(internalBuff.buf)

		bufLen := int(internalBuff.len)

		bytes = (*[1 << 30]byte)(outBuff)[:bufLen:bufLen]
	}

	return bytes
}

func (param *Param) SetKVP(data map[string]string) *Param {
	if param.rodsType == KeyValPair_MS_T {
		kvp := (*C.keyValPair_t)(param.ptr.inOutStruct)

		for key, value := range data {
			C.addKeyVal(kvp, C.CString(key), C.CString(value))
		}

	}
	return param
}

func (param *Param) SetInt(val int) *Param {
	if param.rodsType == INT_MS_T {
		*((*C.int)(param.ptr.inOutStruct)) = C.int(val)
	}
	return param
}

func (param *Param) SetString(val string) *Param {
	if param.rodsType == STR_MS_T {
		param.ptr.inOutStruct = unsafe.Pointer(C.CString(val))
	}
	return param
}

func (param *Param) SetDataObjInp(input map[string]interface{}) *Param {
{'fraction_non_alphanumeric': 0.14672835426305353, 'fraction_numerical': 0.0019828155981493722, 'mean_word_length': 4.255208333333333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3041496', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1183, 'n_words': 248}