{"id":5340,"date":"2021-04-16T09:45:14","date_gmt":"2021-04-16T01:45:14","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=5340"},"modified":"2021-04-16T09:45:15","modified_gmt":"2021-04-16T01:45:15","slug":"gbase-8a%e4%b8%80%e4%b8%aacudf%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/5340","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u4e00\u4e2aCUDF\u6837\u4f8b"},"content":{"rendered":"<p>\u672c\u6587\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u91c7\u7528C\u7f16\u5199UDF\u7684\u6837\u4f8b\u4ee3\u7801\uff0c\u4ec5\u4f9b\u53c2\u8003\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;gbase_global.h>\n#include &lt;gbase_sys.h>\n#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;m_string.h>\n#include &lt;gbase.h>\n#include &lt;ctype.h>\n#include &lt;string.h>\n#include &lt;time.h>\n\n#define MAX_RES_LEN (255*3+1)\n\nvoid Getpartid(unsigned char *key,int len,unsigned long *nr1,unsigned long *nr2)\n{\n        unsigned char sort_order&#91;4] = {0};\n        sort_order&#91;0] = *key;\n        const unsigned char *end= key + len;\n        for (; key &lt; (unsigned char*) end ; key++)\n        {\n                nr1&#91;0]^=(unsigned long)((((unsigned int)nr1&#91;0] &amp; 63) + nr2&#91;0]) * ((unsigned int) *key)) + (nr1&#91;0] &lt;&lt;8 );\n                nr2&#91;0]+=3;\n        }\n}\n\nmy_bool getkeypartid_init(UDF_INIT *initid, UDF_ARGS *args, char *message)\n{\n\tif (args->arg_count != 2 ) \n\t{\n\t\tstrcpy(message, \"Input params count is error!\");\n\t\treturn;\n\t}\n\t\n\targs->arg_type&#91;0] = INT_RESULT;\n\targs->arg_type&#91;1] = INT_RESULT;\t\n\n\tinitid->maybe_null = 1;  \n\tinitid->extension = NULL;  \n\tinitid->max_length = args->lengths&#91;0] > 20 ? args->lengths&#91;0] : 20; \/\/\u6700\u5927\u8fd4\u56de\u503c\u4e0d\u4f1a\u8d85\u8fc7\u53c2\u6570\u4e00\u7684\u6700\u5927\u957f\u5ea6\n\n\t\/\/\u6700\u5927\u957f\u5ea6\u5982\u679c\u8d85\u8fc7\u9884\u5206\u914d\u7684\u5185\u5b58\u5927\u5c0f\uff0c\u91cd\u65b0\u5206\u914d\u4e00\u5757\u5185\u5b58\u5b58\u653e\u7ed3\u679c\n\tif (initid->max_length  > MAX_RES_LEN)\n\t{\n\t\tinitid->ptr = (char *) malloc(initid->max_length);\n\t\tif(initid->ptr == NULL)\n\t\t{\n\t\t\tstrcpy(message, \"Malloc failed.\");\n\t\t\treturn 1;\n\t\t}\n\t\tmemset(initid->ptr,0,initid->max_length);\n\t}\n\t\n\treturn 0;\n}\n\nchar * getkeypartid(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)\n{\n\tunsigned char value&#91;4]={0};\n        int orivalue = *(int*)args->args&#91;0];\n\t\n\tunsigned long returnval=0;\t\n\n        value&#91;0]=(unsigned char) (orivalue)       &amp; 0xFF;\n        value&#91;1]=(unsigned char) (orivalue >> 8)  &amp; 0xFF;\n        value&#91;2]=(unsigned char) (orivalue >> 16) &amp; 0xFF;\n        value&#91;3]=(unsigned char) (orivalue >> 24) &amp; 0xFF;\n        unsigned long nr1 = 1;\n        unsigned long nr2 = 4;\n        Getpartid(value,4,&amp;nr1,&amp;nr2);\n\treturnval=((unsigned int)(nr1)%(*(int*)(args->args&#91;1]))+1);\n\n\tsprintf((char *)result,\"%d\",returnval);\n\t*length =  args->lengths&#91;1];\n        return result;\n\n}\n   \nvoid  getkeypartid_deinit(UDF_INIT *initid)\n{\n\tif (initid->ptr)\n\t{\n\t\tfree(initid->ptr);\n\t\tinitid->ptr = NULL;\n\t}\n}\n\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u91c7\u7528C\u7f16\u5199UDF\u7684\u6837\u4f8b\u4ee3\u7801\uff0c\u4ec5\u4f9b\u53c2\u8003\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-5340","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=5340"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5340\/revisions"}],"predecessor-version":[{"id":5341,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5340\/revisions\/5341"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=5340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=5340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=5340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}