summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2019-03-29 16:57:59 -0400
committerGitHub <noreply@github.com>2019-03-29 16:57:59 -0400
commitb9bf643ec5313b48d74d00bd775056a700f545a2 (patch)
tree7127c0a6a38d9c7c637f4b1e384df9bc2a9bb64d
parente76e75f6e3f499890565ff6d5769550842a16178 (diff)
downloadsdl_android-b9bf643ec5313b48d74d00bd775056a700f545a2.tar.gz
Remove arch dependant bson lib (#1023)
* Integrate new bson lib Due to the nature of not knowing what systems the Java libs will run on, it makes sense to use a pure java based implementation of BSON encoding/decoding until the Livio C lib can be compiled for more architectures, or made on the fly.
-rw-r--r--base/src/main/java/com/livio/BSON/BsonEncoder.java87
-rw-r--r--javaEE/build.gradle2
-rw-r--r--javaSE/build.gradle1
-rw-r--r--javaSE/libs/bson_java_lib.jarbin36302 -> 0 bytes
-rw-r--r--javaSE/src/main/java/com/smartdevicelink/BuildConfig.java2
-rw-r--r--third_party.md6
6 files changed, 96 insertions, 2 deletions
diff --git a/base/src/main/java/com/livio/BSON/BsonEncoder.java b/base/src/main/java/com/livio/BSON/BsonEncoder.java
new file mode 100644
index 000000000..9be61a62d
--- /dev/null
+++ b/base/src/main/java/com/livio/BSON/BsonEncoder.java
@@ -0,0 +1,87 @@
+package com.livio.BSON;
+
+import com.smartdevicelink.util.DebugTool;
+import org.bson.*;
+
+import java.util.*;
+
+public class BsonEncoder {
+
+
+ public static byte[] encodeToBytes(HashMap<String, Object> map) throws ClassCastException {
+ if(map != null) {
+ BasicBSONObject bson = new BasicBSONObject();
+ bson.putAll(sanitizeMap(map));
+ BasicBSONEncoder encoder = new BasicBSONEncoder();
+
+ return encoder.encode(bson);
+ }
+ DebugTool.logError("Something went wrong encoding the map into BSON bytes");
+
+ return null;
+ }
+
+ public static HashMap<String, Object> decodeFromBytes(byte[] bytes) {
+ if(bytes != null) {
+ BasicBSONDecoder decoder = new BasicBSONDecoder();
+ BSONObject object = decoder.readObject(bytes);
+ if (object != null) {
+ Map<String, Object> map = object.toMap();
+ if (map != null) {
+ return sanitizeMap(new HashMap<>(map));
+ }
+ }
+ }
+ DebugTool.logError("Something went wrong decoding bytes into BSON");
+ return null;
+ }
+
+ /**
+ * Goes thorugh the map and ensures that all the values included are supported by SDL. If they are not of a supported
+ * value it is removed from the map
+ * @param map the map to be sanitized
+ * @return a sanitized HashMap with non-supported object type removes
+ */
+ private static HashMap<String, Object> sanitizeMap(HashMap<String, Object> map){
+ Set<String> keys = map.keySet();
+ Object value;
+ for(String key : keys){
+ value = map.get(key);
+
+ //First check to see if it value is a valid type used in SDL
+ if(isSupportedType(value)){
+ continue;
+ }else if(value instanceof List){ //Next, check to see if it is a list of values
+ List list = (List)value;
+
+ //If the list is empty, there shouldn't be a problem leaving it in the map
+ if(list.isEmpty()){
+ continue;
+ }
+
+ //Since the list isn't empty, check the first item
+ if(isSupportedType(list.get(0))){
+ continue;
+ }
+ }
+ //If the item isn't valid, remove it from the map
+ map.remove(key);
+
+ }
+ return map;
+ }
+
+ /**
+ * Checks the value to ensure it is of a supported type
+ * @param value the generic object value
+ * @return if the object is an instanceOf one of the supported SDL BSON objects
+ */
+ private static boolean isSupportedType(Object value){
+ return value instanceof Integer
+ || value instanceof Long
+ || value instanceof Double
+ || value instanceof String
+ || value instanceof Boolean;
+ }
+
+} \ No newline at end of file
diff --git a/javaEE/build.gradle b/javaEE/build.gradle
index da4f0d716..530e10a54 100644
--- a/javaEE/build.gradle
+++ b/javaEE/build.gradle
@@ -27,7 +27,7 @@ configurations {
dependencies {
extraLibs fileTree(dir: 'libs', include: ['*.jar'])
- extraLibs fileTree(dir: '../javaSE/libs', include: ['*.jar']) //BSON lib
+ extraLibs 'org.mongodb:bson:3.10.1'
extraLibs 'com.android.support:support-annotations:28.0.0'
extraLibs 'org.java-websocket:Java-WebSocket:1.3.9'
configurations.api.extendsFrom(configurations.extraLibs)
diff --git a/javaSE/build.gradle b/javaSE/build.gradle
index 0db1e309e..19deb00ad 100644
--- a/javaSE/build.gradle
+++ b/javaSE/build.gradle
@@ -28,6 +28,7 @@ configurations {
dependencies {
extraLibs fileTree(dir: 'libs', include: ['*.jar'])
+ extraLibs 'org.mongodb:bson:3.10.1'
extraLibs 'com.android.support:support-annotations:28.0.0'
extraLibs 'org.java-websocket:Java-WebSocket:1.3.9'
configurations.api.extendsFrom(configurations.extraLibs)
diff --git a/javaSE/libs/bson_java_lib.jar b/javaSE/libs/bson_java_lib.jar
deleted file mode 100644
index 0a6e6500e..000000000
--- a/javaSE/libs/bson_java_lib.jar
+++ /dev/null
Binary files differ
diff --git a/javaSE/src/main/java/com/smartdevicelink/BuildConfig.java b/javaSE/src/main/java/com/smartdevicelink/BuildConfig.java
index 177977930..b24138cc8 100644
--- a/javaSE/src/main/java/com/smartdevicelink/BuildConfig.java
+++ b/javaSE/src/main/java/com/smartdevicelink/BuildConfig.java
@@ -1,5 +1,5 @@
package com.smartdevicelink;
public final class BuildConfig {
- public static final String VERSION_NAME = "RC1-4.8.0";
+ public static final String VERSION_NAME = "RC2-4.8.0";
} \ No newline at end of file
diff --git a/third_party.md b/third_party.md
index f1a9ee943..aed363637 100644
--- a/third_party.md
+++ b/third_party.md
@@ -74,6 +74,12 @@ The third party software included and used by this project is:
* Licensed under Apache License, Version 2.0
* See [https://services.gradle.org/distributions/gradle-4.4-all.zip](https://services.gradle.org/distributions/gradle-4.4-all.zip)
+**BSON - MongoDB**
+
+* `org.mongodb:bson`
+* Licensed under Apache License, Version 2.0
+* See [https://mvnrepository.com/artifact/org.mongodb/bson/3.10.1](https://mvnrepository.com/artifact/org.mongodb/bson/3.10.1)
+
### SDL JavaEE