mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
增加一个指定数据类型为int64的方法 (#1241)
* Update lua-bson.c * 增加一个指定数据类型为int64的方法 * 修改一些类型错误 * Invalid date -> Invalid int64
This commit is contained in:
@@ -395,6 +395,14 @@ append_one(struct bson *bs, lua_State *L, const char *key, size_t sz, int depth)
|
|||||||
case BSON_MAXKEY:
|
case BSON_MAXKEY:
|
||||||
case BSON_NULL:
|
case BSON_NULL:
|
||||||
break;
|
break;
|
||||||
|
case BSON_INT64: {
|
||||||
|
if (len != 2 + 8) {
|
||||||
|
luaL_error(L, "Invalid int64");
|
||||||
|
}
|
||||||
|
const int64_t * v = (const int64_t *)(str + 2);
|
||||||
|
write_int64(bs, *v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
luaL_error(L,"Invalid subtype %d", subt);
|
luaL_error(L,"Invalid subtype %d", subt);
|
||||||
}
|
}
|
||||||
@@ -1015,6 +1023,19 @@ ldate(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
lint64(lua_State *L) {
|
||||||
|
int64_t d = luaL_checkinteger(L, 1);
|
||||||
|
luaL_Buffer b;
|
||||||
|
luaL_buffinit(L, &b);
|
||||||
|
luaL_addchar(&b, 0);
|
||||||
|
luaL_addchar(&b, BSON_INT64);
|
||||||
|
luaL_addlstring(&b, (const char *)&d, sizeof(d));
|
||||||
|
luaL_pushresult(&b);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ltimestamp(lua_State *L) {
|
ltimestamp(lua_State *L) {
|
||||||
int d = luaL_checkinteger(L,1);
|
int d = luaL_checkinteger(L,1);
|
||||||
@@ -1145,9 +1166,18 @@ lsubtype(lua_State *L, int subtype, const uint8_t * buf, size_t sz) {
|
|||||||
case BSON_DBPOINTER:
|
case BSON_DBPOINTER:
|
||||||
case BSON_SYMBOL:
|
case BSON_SYMBOL:
|
||||||
case BSON_CODEWS:
|
case BSON_CODEWS:
|
||||||
lua_pushvalue(L, lua_upvalueindex(13));
|
lua_pushvalue(L, lua_upvalueindex(14));
|
||||||
lua_pushlstring(L, (const char *)buf, sz);
|
lua_pushlstring(L, (const char *)buf, sz);
|
||||||
return 2;
|
return 2;
|
||||||
|
case BSON_INT64: {
|
||||||
|
if (sz != 8) {
|
||||||
|
return luaL_error(L, "Invalid int64");
|
||||||
|
}
|
||||||
|
int64_t d = *(const int64_t *)buf;
|
||||||
|
lua_pushvalue(L, lua_upvalueindex(13));
|
||||||
|
lua_pushinteger(L, d);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return luaL_error(L, "Invalid subtype %d", subtype);
|
return luaL_error(L, "Invalid subtype %d", subtype);
|
||||||
}
|
}
|
||||||
@@ -1203,7 +1233,8 @@ typeclosure(lua_State *L) {
|
|||||||
"regex", // 10
|
"regex", // 10
|
||||||
"minkey", // 11
|
"minkey", // 11
|
||||||
"maxkey", // 12
|
"maxkey", // 12
|
||||||
"unsupported", // 13
|
"int64", // 13
|
||||||
|
"unsupported", // 14
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
int n = sizeof(typename)/sizeof(typename[0]);
|
int n = sizeof(typename)/sizeof(typename[0]);
|
||||||
@@ -1305,6 +1336,7 @@ luaopen_bson(lua_State *L) {
|
|||||||
{ "regex", lregex },
|
{ "regex", lregex },
|
||||||
{ "binary", lbinary },
|
{ "binary", lbinary },
|
||||||
{ "objectid", lobjectid },
|
{ "objectid", lobjectid },
|
||||||
|
{ "int64", lint64 },
|
||||||
{ "decode", ldecode },
|
{ "decode", ldecode },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user