Skip to content

Commit

Permalink
feat(android): serialization support version 15 data
Browse files Browse the repository at this point in the history
serialization support version 15 data and
decouples related types and their dependencies.
  • Loading branch information
medns committed Sep 23, 2022
1 parent d30ee95 commit 2986115
Show file tree
Hide file tree
Showing 22 changed files with 797 additions and 502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.tencent.mtt.hippy.runtime.builtins.wasm.WasmModule;
import com.tencent.mtt.hippy.serialization.exception.DataCloneDeserializationException;
import com.tencent.mtt.hippy.serialization.recommend.Deserializer;
import com.tencent.mtt.hippy.serialization.recommend.SharedValueConveyor;

@SuppressWarnings("unused")
public class DeserializerDelegate implements Deserializer.Delegate {
Expand Down Expand Up @@ -49,4 +50,9 @@ public JSSharedArrayBuffer getSharedArrayBufferFromId(Deserializer deserializer,
public WasmModule getWasmModuleFromId(Deserializer deserializer, int transfer_id) {
return NativeAccess.getWasmModuleFromId(transfer_id);
}

@Override
public SharedValueConveyor getSharedValueConveyor(Deserializer deserializer) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.tencent.mtt.hippy.runtime.builtins.JSValue;
import com.tencent.mtt.hippy.runtime.builtins.wasm.WasmModule;
import com.tencent.mtt.hippy.serialization.recommend.Serializer;
import com.tencent.mtt.hippy.serialization.recommend.SharedValueConveyor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -46,6 +47,11 @@ public boolean writeHostObject(Serializer serializer, Object object) {
return false;
}

@Override
public boolean adoptSharedValueConveyor(Serializer serializer, SharedValueConveyor conveyor) {
return false;
}

// region set & set
private <T extends JSValue> int getObjectId(T object) {
int id = nextId.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ public enum DataViewKind {
UINT32_ARRAY, // kUint32Array
FLOAT32_ARRAY, // kFloat32Array
FLOAT64_ARRAY, // kFloat64Array
BIGINT64_ARRAY, // kBigInt64Array
BIGUINT64_ARRAY, // kBigUint64Array
DATA_VIEW // kDataView
}

private T bufferObject;
private DataViewKind kind;
private final int flags;
private final String BYTE_OFFSET = "byteOffset";
private final String BYTE_LENGTH = "byteLength";

public JSDataView(T bufferObject, DataViewKind kind, int byteOffset, int byteLength) {
public JSDataView(T bufferObject, DataViewKind kind, int byteOffset, int byteLength, int flags) {
this.bufferObject = bufferObject;
this.kind = kind;
this.flags = flags;
set(BYTE_OFFSET, byteOffset);
set(BYTE_LENGTH, byteLength);
}
Expand All @@ -51,6 +55,10 @@ public DataViewKind getKind() {
return kind;
}

public int getFlags() {
return flags;
}

public T getBufferObject() {
return bufferObject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public enum ArrayBufferViewTag {
UINT32_ARRAY('D'), // kUint32Array
FLOAT32_ARRAY('f'), // kFloat32Array
FLOAT64_ARRAY('F'), // kFloat64Array
BIGINT64_ARRAY('q'), // kBigInt64Array
BIGUINT64_ARRAY('Q'), // kBigUint64Array
DATA_VIEW('?'); // kDataView

private final byte tag;

@SuppressWarnings("unused")
ArrayBufferViewTag(char tag) {
this.tag = (byte) tag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/**
* Error-related serialization tags.
*/
@SuppressWarnings({"unused"})
public enum ErrorTag {
EVAL_ERROR('E'), // kEvalErrorPrototype
RANGE_ERROR('R'), // kRangeErrorPrototype
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
*/
package com.tencent.mtt.hippy.serialization;

public interface JSSerializationTag {
byte TRUE_OBJECT = (byte) 'y'; // kTrueObject
byte FALSE_OBJECT = (byte) 'x'; // kFalseObject
byte NUMBER_OBJECT = (byte) 'n'; // kNumberObject
byte BIG_INT_OBJECT = (byte) 'z'; // kBigIntObject
byte STRING_OBJECT = (byte) 's'; // kStringObject
byte REGEXP = (byte) 'R'; // kRegExp
byte ARRAY_BUFFER = (byte) 'B'; // kArrayBuffer
byte SHARED_ARRAY_BUFFER = (byte) 'u'; // kSharedArrayBuffer
byte ARRAY_BUFFER_TRANSFER = (byte) 't'; // kArrayBufferTransfer
byte ARRAY_BUFFER_VIEW = (byte) 'V'; // kArrayBufferView
byte BEGIN_JS_MAP = (byte) ';'; // kBeginJSMap
byte END_JS_MAP = (byte) ':'; // kEndJSMap
byte BEGIN_JS_SET = (byte) '\''; // kBeginJSSet
byte END_JS_SET = (byte) ','; // kEndJSSet
byte BEGIN_JS_OBJECT = (byte) 'o'; // kBeginJSObject
byte END_JS_OBJECT = (byte) '{'; // kEndJSObject
byte BEGIN_SPARSE_JS_ARRAY = (byte) 'a'; // kBeginSparseJSArray
byte END_SPARSE_JS_ARRAY = (byte) '@'; // kEndSparseJSArray
byte BEGIN_DENSE_JS_ARRAY = (byte) 'A'; // kBeginDenseJSArray
byte END_DENSE_JS_ARRAY = (byte) '$'; // kEndDenseJSArray
byte SHARED_OBJECT = (byte) 'p'; // kSharedObject
byte WASM_MODULE_TRANSFER = (byte) 'w'; // kWasmModuleTransfer
byte HOST_OBJECT = (byte) '\\'; // kHostObject
byte WASM_MEMORY_TRANSFER = (byte) 'm'; // kWasmMemoryTransfer
byte ERROR = (byte) 'r'; // kError
}

0 comments on commit 2986115

Please sign in to comment.