diff options
Diffstat (limited to 'base/android')
-rw-r--r-- | base/android/jni_array.cc | 13 | ||||
-rw-r--r-- | base/android/jni_array.h | 6 |
2 files changed, 19 insertions, 0 deletions
diff --git a/base/android/jni_array.cc b/base/android/jni_array.cc index 6c7ac5b..3c06413 100644 --- a/base/android/jni_array.cc +++ b/base/android/jni_array.cc @@ -167,6 +167,19 @@ void JavaIntArrayToIntVector(JNIEnv* env, env->ReleaseIntArrayElements(int_array, ints, JNI_ABORT); } +void JavaLongArrayToLongVector(JNIEnv* env, + jlongArray long_array, + std::vector<long>* out) { + DCHECK(out); + out->clear(); + jsize len = env->GetArrayLength(long_array); + jlong* longs = env->GetLongArrayElements(long_array, NULL); + for (jsize i = 0; i < len; ++i) { + out->push_back(static_cast<long>(longs[i])); + } + env->ReleaseLongArrayElements(long_array, longs, JNI_ABORT); +} + void JavaFloatArrayToFloatVector(JNIEnv* env, jfloatArray float_array, std::vector<float>* out) { diff --git a/base/android/jni_array.h b/base/android/jni_array.h index 9d9be67..66b9422 100644 --- a/base/android/jni_array.h +++ b/base/android/jni_array.h @@ -73,6 +73,12 @@ BASE_EXPORT void JavaIntArrayToIntVector( jintArray int_array, std::vector<int>* out); +// Replaces the content of |out| with the Java longs in |long_array|. +BASE_EXPORT void JavaLongArrayToLongVector( + JNIEnv* env, + jlongArray long_array, + std::vector<long>* out); + // Replaces the content of |out| with the Java floats in |float_array|. BASE_EXPORT void JavaFloatArrayToFloatVector( JNIEnv* env, |