예제 #1
0
void Msg_Struct::build_buffer_map(const Field_Info &field_info, Block_Buffer &buffer, Isolate* isolate, v8::Local<v8::Value> value) {
    if (!value->IsMap()) {
        LOG_ERROR("field_name:%s is not map, struct_name:%s", field_info.field_name.c_str(), struct_name().c_str());
        buffer.write_uint16(0);
        return;
    }

    Local<Map> map = Local<Map>::Cast(value);
    int16_t len = map->Size();
    buffer.write_uint16(len);
    Local<Array> array = map->AsArray();
    //index N is the Nth key and index N + 1 is the Nth value.
    if(is_struct(field_info.field_type)) {
        for (int i = 0; i < len * 2; i = i + 2) {
            Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
            build_buffer_struct(field_info, buffer, isolate, element);
        }
    }
    else {
        Field_Info key_info;
        key_info.field_label = "args";
        key_info.field_type = field_info.key_type;
        key_info.field_name = field_info.key_name;
        for (int i = 0; i < len * 2; i = i + 2) {
            Local<Value> key = array->Get(isolate->GetCurrentContext(), i).ToLocalChecked();
            Local<Value> element = array->Get(isolate->GetCurrentContext(), i + 1).ToLocalChecked();
            build_buffer_struct(key_info, buffer, isolate, key);
            build_buffer_struct(field_info, buffer, isolate, element);
        }
    }
}
예제 #2
0
result_t util_base::isMap(v8::Local<v8::Value> v, bool& retVal)
{
    retVal = v->IsMap();
    return 0;
}