本文整理汇总了C++中Local::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::Write方法的具体用法?C++ Local::Write怎么用?C++ Local::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Value
void StringIMPL::Value(wchar_t *target) const
{
Isolate::Scope isolate_scope(g_CurrentVM);
HandleScope handle_scope(g_CurrentVM);
Local<Context> context = v8::Local<v8::Context>::New(g_CurrentVM, g_GlobalContext);
Context::Scope context_scope(context);
Local<v8::String> stringValue = Handle<v8::String>::New(g_CurrentVM, persisted_value);
stringValue->Write((uint16_t *)target);
}
示例2:
jsvalue JsEngine::StringFromV8(Handle<Value> value)
{
jsvalue v;
Local<String> s = value->ToString();
v.length = s->Length();
v.value.str = new uint16_t[v.length+1];
if (v.value.str != NULL) {
s->Write(v.value.str);
v.type = JSVALUE_TYPE_STRING;
}
return v;
}
示例3: DecodeWrite
// Returns number of bytes written.
ssize_t DecodeWrite(char *buf,
size_t buflen,
Handle<Value> val,
enum encoding encoding) {
HandleScope scope;
// XXX
// A lot of improvement can be made here. See:
// http://code.google.com/p/v8/issues/detail?id=270
// http://groups.google.com/group/v8-dev/browse_thread/thread/dba28a81d9215291/ece2b50a3b4022c
// http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611
if (val->IsArray()) {
fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
"Use 'binary'.\n");
assert(0);
return -1;
}
Local<String> str = val->ToString();
if (encoding == UTF8) {
str->WriteUtf8(buf, buflen, NULL, String::HINT_MANY_WRITES_EXPECTED);
return buflen;
}
if (encoding == ASCII) {
str->WriteAscii(buf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
return buflen;
}
// THIS IS AWFUL!!! FIXME
assert(encoding == BINARY);
uint16_t * twobytebuf = new uint16_t[buflen];
str->Write(twobytebuf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
for (size_t i = 0; i < buflen; i++) {
unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
buf[i] = b[0];
}
delete [] twobytebuf;
return buflen;
}
示例4: GetParametersFromArray
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
*paramCount = values->Length();
Parameter* params = (Parameter *) malloc(*paramCount * sizeof(Parameter));
for (int i = 0; i < *paramCount; i++) {
Local<Value> value = values->Get(i);
params[i].size = 0;
params[i].length = SQL_NULL_DATA;
params[i].buffer_length = 0;
params[i].decimals = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - ¶m[%i].length = %X\n",
i, ¶ms[i].length);
if (value->IsString()) {
Local<String> string = value->ToString();
int length = string->Length();
params[i].c_type = SQL_C_TCHAR;
#ifdef UNICODE
params[i].type = (length >= 8000) ? SQL_WLONGVARCHAR : SQL_WVARCHAR;
params[i].buffer_length = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
params[i].type = (length >= 8000) ? SQL_LONGVARCHAR : SQL_VARCHAR;
params[i].buffer_length = string->Utf8Length() + 1;
#endif
params[i].buffer = malloc(params[i].buffer_length);
params[i].size = params[i].buffer_length;
params[i].length = SQL_NTS;//params[i].buffer_length;
#ifdef UNICODE
string->Write((uint16_t *) params[i].buffer);
#else
string->WriteUtf8((char *) params[i].buffer);
#endif
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%s\n", i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
(char*) params[i].buffer);
}
else if (value->IsNull()) {
params[i].c_type = SQL_C_DEFAULT;
params[i].type = SQL_VARCHAR;
params[i].length = SQL_NULL_DATA;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length);
}
else if (value->IsInt32()) {
int64_t *number = new int64_t(value->IntegerValue());
params[i].c_type = SQL_C_SBIGINT;
params[i].type = SQL_BIGINT;
params[i].buffer = number;
params[i].length = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%lld\n", i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
*number);
}
else if (value->IsNumber()) {
double *number = new double(value->NumberValue());
params[i].c_type = SQL_C_DOUBLE;
params[i].type = SQL_DECIMAL;
params[i].buffer = number;
params[i].buffer_length = sizeof(double);
params[i].length = params[i].buffer_length;
params[i].decimals = 7;
params[i].size = sizeof(double);
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i "
"value=%f\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length,
*number);
}
else if (value->IsBoolean()) {
bool *boolean = new bool(value->BooleanValue());
params[i].c_type = SQL_C_BIT;
params[i].type = SQL_BIT;
params[i].buffer = boolean;
params[i].length = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] "
"c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
i, params[i].c_type, params[i].type,
params[i].buffer_length, params[i].size, params[i].length);
}
}
//.........这里部分代码省略.........
示例5: GetParametersFromArray
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
*paramCount = values->Length();
Parameter* params = NULL;
if (*paramCount > 0) {
params = (Parameter *) malloc(*paramCount * sizeof(Parameter));
}
for (int i = 0; i < *paramCount; i++) {
Local<Value> value = values->Get(i);
params[i].ColumnSize = 0;
params[i].StrLen_or_IndPtr = SQL_NULL_DATA;
params[i].BufferLength = 0;
params[i].DecimalDigits = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - param[%i].length = %lli\n",
i, params[i].StrLen_or_IndPtr);
if (value->IsString()) {
Local<String> string = value->ToString();
int length = string->Length();
params[i].ValueType = SQL_C_TCHAR;
params[i].ColumnSize = 0; //SQL_SS_LENGTH_UNLIMITED
#ifdef UNICODE
params[i].ParameterType = SQL_WVARCHAR;
params[i].BufferLength = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
params[i].ParameterType = SQL_VARCHAR;
params[i].BufferLength = string->Utf8Length() + 1;
#endif
params[i].ParameterValuePtr = malloc(params[i].BufferLength);
params[i].StrLen_or_IndPtr = SQL_NTS;//params[i].BufferLength;
#ifdef UNICODE
string->Write((uint16_t *) params[i].ParameterValuePtr);
#else
string->WriteUtf8((char *) params[i].ParameterValuePtr);
#endif
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%s\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
(char*) params[i].ParameterValuePtr);
}
else if (value->IsNull()) {
params[i].ValueType = SQL_C_DEFAULT;
params[i].ParameterType = SQL_VARCHAR;
params[i].StrLen_or_IndPtr = SQL_NULL_DATA;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
}
else if (value->IsInt32()) {
int64_t *number = new int64_t(value->IntegerValue());
params[i].ValueType = SQL_C_SBIGINT;
params[i].ParameterType = SQL_BIGINT;
params[i].ParameterValuePtr = number;
params[i].StrLen_or_IndPtr = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%lld\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
*number);
}
else if (value->IsNumber()) {
double *number = new double(value->NumberValue());
params[i].ValueType = SQL_C_DOUBLE;
params[i].ParameterType = SQL_DECIMAL;
params[i].ParameterValuePtr = number;
params[i].BufferLength = sizeof(double);
params[i].StrLen_or_IndPtr = params[i].BufferLength;
params[i].DecimalDigits = 7;
params[i].ColumnSize = sizeof(double);
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%f\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
*number);
}
else if (value->IsBoolean()) {
bool *boolean = new bool(value->BooleanValue());
params[i].ValueType = SQL_C_BIT;
params[i].ParameterType = SQL_BIT;
params[i].ParameterValuePtr = boolean;
params[i].StrLen_or_IndPtr = 0;
DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
i, params[i].ValueType, params[i].ParameterType,
params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
}
}
return params;
}