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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef VPP_JVPP_CORE_H
17 #define VPP_JVPP_CORE_H
19 #include <vlibapi/api_types.h>
21 #endif //VPP_JVPP_CORE_H
24 // * Host to network byte order conversion for string type. Converts String in Java to VPP string type.
29 // * } __attribute__ ((packed)) vl_api_string_t;
31 static void _host_to_net_string(JNIEnv * env, jstring javaString, vl_api_string_t * _net)
33 const char *nativeString = (*env)->GetStringUTFChars(env, javaString, 0);
34 int len = strlen(nativeString);
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)
40 vl_api_string->length = len;
41 memcpy(vl_api_string->buf, nativeString, len);
44 (*env)->ReleaseStringUTFChars(env, javaString, nativeString);
49 // * Network to host byte order conversion for string type. Converts VPP string type to String in Java
54 // * } __attribute__ ((packed)) vl_api_string_t;
56 static jstring _net_to_host_string(JNIEnv * env, const vl_api_string_t * _net)
58 jstring jstr = (*env)->NewStringUTF(env, (char *)_net->buf);