-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from Tencent/dev
support golang
- Loading branch information
Showing
12 changed files
with
1,537 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Core/ | ||
Makefile | ||
libmmkv.* | ||
*.cbp | ||
Testing/ | ||
tencent.com/ | ||
install_manifest.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Tencent is pleased to support the open source community by making | ||
# MMKV available. | ||
# | ||
# Copyright (C) 2020 THL A29 Limited, a Tencent company. | ||
# All rights reserved. | ||
# | ||
# Licensed under the BSD 3-Clause License (the "License"); you may not use | ||
# this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# https://opensource.org/licenses/BSD-3-Clause | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.8.0) | ||
|
||
project(mmkv) | ||
|
||
IF(APPLE) | ||
add_compile_definitions(FORCE_POSIX) | ||
ENDIF() | ||
|
||
add_subdirectory(../../Core Core) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
add_library( # Sets the name of the library. | ||
mmkv | ||
|
||
# Sets the library as a shared library. | ||
STATIC | ||
|
||
# Provides a relative path to your source file(s). | ||
golang-bridge.h | ||
golang-bridge.cpp | ||
) | ||
|
||
target_include_directories(mmkv PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
set_target_properties(mmkv PROPERTIES | ||
CXX_STANDARD 17 | ||
CXX_EXTENSIONS OFF | ||
) | ||
|
||
# Specifies libraries CMake should link to your target library. You | ||
# can link multiple libraries, such as libraries you define in this | ||
# build script, prebuilt third-party libraries, or system libraries. | ||
|
||
target_link_libraries( mmkv | ||
core | ||
pthread | ||
) | ||
|
||
# Install source file & library to tencent.com/mmkv dir | ||
|
||
install(FILES mmkv.go callback.go go.mod mmkv_test.go golang-bridge.h golang-bridge.cpp | ||
DESTINATION "tencent.com/mmkv") | ||
|
||
install(FILES libmmkv.a Core/libcore.a | ||
DESTINATION "tencent.com/mmkv/lib") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making | ||
* MMKV available. | ||
* | ||
* Copyright (C) 2020 THL A29 Limited, a Tencent company. | ||
* All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// MMKV is a cross-platform key-value storage framework developed by WeChat. | ||
package mmkv | ||
|
||
/* | ||
#include "golang-bridge.h" | ||
#include <stdlib.h> | ||
*/ | ||
import "C" | ||
|
||
// the callback type of Logger | ||
type LogHandler func(level int, file string, line int, function string, message string) | ||
|
||
var gLogHandler LogHandler | ||
|
||
// register a log callback | ||
func RegisterLogHandler(logHandler LogHandler) { | ||
gLogHandler = logHandler | ||
|
||
C.setWantsLogRedirect(C.bool(true)) | ||
} | ||
|
||
// unregister a log callback | ||
func UnRegisterLogHandler() { | ||
gLogHandler = nil | ||
|
||
C.setWantsLogRedirect(C.bool(false)) | ||
} | ||
|
||
//export myLogHandler | ||
func myLogHandler(level int, file string, line int, function string, message string) { | ||
if gLogHandler != nil { | ||
gLogHandler(level, file, line, function, message) | ||
} | ||
} | ||
|
||
const ( | ||
OnErrorDiscard = iota // When there's an error, MMKV will discard everything by default. | ||
OnErrorRecover // When there's an error, MMKV will try to recover as much data as possible. | ||
) | ||
|
||
const ( | ||
MMKVCRCCheckFail = iota | ||
MMKVFileLength | ||
) | ||
|
||
// the callback type of error handler | ||
// error is either MMKVCRCCheckFail or MMKVFileLength | ||
// return OnErrorDiscard (default) or OnErrorRecover | ||
type ErrorHandler func(mmapID string, error int) int | ||
|
||
var gErrorHandler ErrorHandler | ||
|
||
// register a error callback | ||
func RegisterErrorHandler(errorHandler ErrorHandler) { | ||
gErrorHandler = errorHandler | ||
|
||
C.setWantsErrorHandle(C.bool(true)) | ||
} | ||
|
||
// unregister a error callback | ||
func UnRegisterErrorHandler() { | ||
gErrorHandler = nil | ||
|
||
C.setWantsErrorHandle(C.bool(false)) | ||
} | ||
|
||
//export myErrorHandler | ||
func myErrorHandler(mmapID string, error int) int { | ||
if gErrorHandler != nil { | ||
return gErrorHandler(mmapID, error) | ||
} | ||
return OnErrorDiscard | ||
} | ||
|
||
// the type of content change handler | ||
type ContentChangeHandler func(mmapID string) | ||
|
||
var gContentChangeHandler ContentChangeHandler | ||
|
||
// register a content change callback | ||
func RegisterContentChangeHandler(contentChangeHandler ContentChangeHandler) { | ||
gContentChangeHandler = contentChangeHandler | ||
|
||
C.setWantsContentChangeHandle(C.bool(true)) | ||
} | ||
|
||
// unregister a content change callback | ||
func UnRegisterContentChangeHandler() { | ||
gContentChangeHandler = nil | ||
|
||
C.setWantsContentChangeHandle(C.bool(false)) | ||
} | ||
|
||
//export myContentChangeHandler | ||
func myContentChangeHandler(mmapID string) { | ||
if gContentChangeHandler != nil { | ||
gContentChangeHandler(mmapID) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module tencent.com/mmkv | ||
|
||
go 1.15 |
Oops, something went wrong.
delete line 31