mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-06 02:30:30 +08:00
v3.1
1. 不使用压缩时字符串在内存直接编解码 2. 减少读取配置次数
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(base1432 VERSION 2.0)
|
||||
|
||||
add_library(base1432 ./base1432le.c)
|
||||
add_library(base14c STATIC base1432le.c)
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(base1464 VERSION 2.0)
|
||||
|
||||
add_library(base1464 ./base1464le.c)
|
||||
add_library(base14c STATIC base1464le.c)
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.10.2)
|
||||
|
||||
project("base16384")
|
||||
|
||||
add_library(base14 SHARED base16384.cpp)
|
||||
|
||||
add_library(base14c STATIC base16384.c)
|
||||
|
||||
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
add_definitions("-DCPUBIT64")
|
||||
add_subdirectory("./64")
|
||||
target_link_libraries(base14c base1464)
|
||||
ELSE()
|
||||
add_definitions("-DCPUBIT32")
|
||||
add_subdirectory("./32")
|
||||
target_link_libraries(base14c base1432)
|
||||
ENDIF()
|
||||
|
||||
target_link_libraries(base14 base14c)
|
||||
add_library(base14 SHARED base16384.cpp)
|
||||
add_library(base14s STATIC base16384.c)
|
||||
target_link_libraries(base14 base14s base14c)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <jni.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "base16384.h"
|
||||
#include <cstring>
|
||||
#include "base16384.hpp"
|
||||
|
||||
#define execute(function){\
|
||||
const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\
|
||||
@@ -12,11 +13,26 @@
|
||||
return re;\
|
||||
}
|
||||
|
||||
extern "C" int encode_file(const char* input, const char* output);
|
||||
extern "C" int decode_file(const char* input, const char* output);
|
||||
#define exe_byte(fun) {\
|
||||
uint32_t len = env->GetArrayLength(buf);\
|
||||
const uint8_t* data = (uint8_t*)env->GetByteArrayElements(buf, JNI_FALSE);\
|
||||
LENDAT* ld = fun(data, len);\
|
||||
jbyteArray out = env->NewByteArray(ld->len);\
|
||||
auto out_data = env->GetByteArrayElements(out, JNI_FALSE);\
|
||||
memcpy(out_data, ld->data, ld->len);\
|
||||
free(ld);\
|
||||
env->ReleaseByteArrayElements(out, out_data, JNI_COMMIT);\
|
||||
return out;\
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file)
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(encode)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(decode)
|
||||
40
app/src/main/cpp/base14/base16384.hpp
Normal file
40
app/src/main/cpp/base14/base16384.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Created by fumiama on 2021/5/20.
|
||||
//
|
||||
|
||||
#ifndef BASE16384_BASE16384_HPP
|
||||
#define BASE16384_BASE16384_HPP
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef CPUBIT32
|
||||
#ifndef CPUBIT64
|
||||
#define CPUBIT32
|
||||
#endif
|
||||
#endif
|
||||
#ifdef CPUBIT32
|
||||
#define B14BUFSIZ 8192
|
||||
struct LENDAT {
|
||||
uint8_t* data;
|
||||
uint32_t len;
|
||||
};
|
||||
typedef struct LENDAT LENDAT;
|
||||
|
||||
extern "C" LENDAT* encode(const uint8_t* data, const u_int32_t len);
|
||||
extern "C" LENDAT* decode(const uint8_t* data, const u_int32_t len);
|
||||
#endif
|
||||
#ifdef CPUBIT64
|
||||
#define B14BUFSIZ 16384
|
||||
struct LENDAT {
|
||||
uint8_t* data;
|
||||
uint64_t len;
|
||||
};
|
||||
typedef struct LENDAT LENDAT;
|
||||
|
||||
extern "C" LENDAT* encode(const uint8_t* data, const u_int64_t len);
|
||||
extern "C" LENDAT* decode(const uint8_t* data, const u_int64_t len);
|
||||
#endif
|
||||
|
||||
extern "C" int encode_file(const char* input, const char* output);
|
||||
extern "C" int decode_file(const char* input, const char* output);
|
||||
|
||||
#endif //BASE16384_BASE16384_HPP
|
||||
Reference in New Issue
Block a user