API: Use string type instead of u8.
[vpp.git] / extras / japi / java / jvpp-core / jvpp_core.h
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef VPP_JVPP_CORE_H
17 #define VPP_JVPP_CORE_H
18
19 #include <vlibapi/api_types.h>
20
21 #endif //VPP_JVPP_CORE_H
22
23 // /**
24 // * Host to network byte order conversion for string type. Converts String in Java to VPP string type.
25 // * typedef struct
26 // * {
27 // *   u32 length;
28 // *   u8 buf[0];
29 // * } __attribute__ ((packed)) vl_api_string_t;
30 // */
31 static void _host_to_net_string(JNIEnv * env, jstring javaString, vl_api_string_t * _net)
32 {
33     const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
34     int len = strlen(nativeString);
35
36     vl_api_string_t * vl_api_string = (vl_api_string_t *)calloc(1, (sizeof(vl_api_string_t) + len * sizeof(u8)));
37     if (NULL == vl_api_string)
38         return;
39
40     vl_api_string->length = len;
41     memcpy(vl_api_string->buf, nativeString, len);
42
43     _net = vl_api_string;
44     (*env)->ReleaseStringUTFChars(env, javaString, nativeString);
45 }
46
47 //
48 // /**
49 // * Network to host byte order conversion for string type. Converts VPP string type to String in Java
50 // * typedef struct
51 // * {
52 // *   u32 length;
53 // *   u8 buf[0];
54 // * } __attribute__ ((packed)) vl_api_string_t;
55 // */
56 static jstring _net_to_host_string(JNIEnv * env, const vl_api_string_t * _net)
57 {
58     jstring jstr = (*env)->NewStringUTF(env, (char *)_net->buf);
59
60     return jstr;
61 }