forked from apache/incubator-weex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
715 additions
and
437 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
81 changes: 81 additions & 0 deletions
81
weex_core/Source/core/data_render/vnode/android/conversion.cc
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,81 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
#ifdef OS_ANDROID | ||
|
||
#include "core/data_render/vnode/android/conversion.h" | ||
#include "android/utils/params_utils.h" | ||
#include "core/data_render/exec_state.h" | ||
#include "core/data_render/object.h" | ||
#include "core/manager/weex_core_manager.h" | ||
#include "wson/wson.h" | ||
#include "wson/wson_parser.h" | ||
|
||
namespace weex { | ||
namespace core { | ||
namespace data_render { | ||
|
||
json11::Json Conversion::GenJSON(const Value* v) { | ||
switch (v->type) { | ||
case Value::Type::NUMBER: | ||
return v->n; | ||
case Value::Type::STRING: | ||
return v->str->c_str(); | ||
case Value::Type::INT: | ||
return static_cast<int>(v->i); | ||
case Value::Type::BOOL: | ||
return v->b; | ||
case Value::Type::ARRAY: { | ||
Array* array = ValueTo<Array>(v); | ||
std::vector<json11::Json> json_array; | ||
for (auto it = array->items.begin(); it != array->items.end(); it++) { | ||
json_array.push_back(GenJSON(&*it)); | ||
} | ||
return json_array; | ||
} | ||
case Value::Type::TABLE: { | ||
Table* table = ValueTo<Table>(v); | ||
std::map<std::string, json11::Json> json_table; | ||
for (auto it = table->map.begin(); it != table->map.end(); it++) { | ||
json_table.insert({it->first, GenJSON(&it->second)}); | ||
} | ||
return json_table; | ||
} | ||
case Value::Type::NIL: | ||
return nullptr; | ||
} | ||
} | ||
|
||
VALUE_WITH_TYPE* Conversion::GenValueWithType(const char* event_str) { | ||
VALUE_WITH_TYPE* event = getValueWithTypePtr(); | ||
event->type = ParamsType::BYTEARRAY; | ||
auto buffer = wson_buffer_new(); | ||
wson_push_type_uint8_string( | ||
buffer, reinterpret_cast<const uint8_t*>(event_str), strlen(event_str)); | ||
event->value.byteArray = genWeexByteArray( | ||
static_cast<const char*>(buffer->data), buffer->position); | ||
buffer->data = nullptr; | ||
wson_buffer_free(buffer); | ||
return event; | ||
} | ||
|
||
} // namespace data_render | ||
} // namespace core | ||
} // namespace weex | ||
|
||
#endif |
45 changes: 45 additions & 0 deletions
45
weex_core/Source/core/data_render/vnode/android/conversion.h
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,45 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
#ifdef OS_ANDROID | ||
|
||
#ifndef CORE_DATA_RENDER_VNODE_ANDROID_CONVERSION_H_ | ||
#define CORE_DATA_RENDER_VNODE_ANDROID_CONVERSION_H_ | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
#include "include/WeexApiHeader.h" | ||
#include "third_party/json11/json11.hpp" | ||
|
||
namespace weex { | ||
namespace core { | ||
namespace data_render { | ||
class Value; | ||
class Conversion { | ||
public: | ||
static json11::Json GenJSON(const Value* v); | ||
static VALUE_WITH_TYPE* GenValueWithType(const char* event_str); | ||
}; | ||
|
||
} // namespace data_render | ||
} // namespace core | ||
} // namespace weex | ||
|
||
#endif // CORE_DATA_RENDER_VNODE_ANDROID_CONVERSION_H_ | ||
#endif |
Oops, something went wrong.