Skip to content

Commit

Permalink
bson扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed May 10, 2024
1 parent 407329b commit ac203fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 2 additions & 0 deletions extend/lbson/src/bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ namespace lbson {
lua_pushinteger(L, read_val<int32_t>(L, slice));
break;
case bson_type::BSON_DATE:
lua_pushinteger(L, read_val<int64_t>(L, slice) / 1000);
break;
case bson_type::BSON_INT64:
case bson_type::BSON_TIMESTAMP:
lua_pushinteger(L, read_val<int64_t>(L, slice));
Expand Down
6 changes: 1 addition & 5 deletions extend/lbson/src/lbson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ namespace lbson {
return new bson_value(bson_type::BSON_DOCUMENT, "");
}
static bson_value* int32(int32_t value) {
return new bson_value(bson_type::BSON_INT64, value);
return new bson_value(bson_type::BSON_INT32, value);
}
static bson_value* int64(int64_t value) {
return new bson_value(bson_type::BSON_INT64, value);
}
static bson_value* date(int64_t value) {
return new bson_value(bson_type::BSON_DATE, value * 1000);
}
static bson_value* timestamp(int64_t value) {
return new bson_value(bson_type::BSON_TIMESTAMP, value);
}

static void init_static_bson() {
for (uint32_t i = 0; i < max_bson_index; ++i) {
Expand All @@ -51,7 +48,6 @@ namespace lbson {
llbson.set_function("encode", encode);
llbson.set_function("decode", decode);
llbson.set_function("mongocodec", mongo_codec);
llbson.set_function("timestamp", timestamp);
llbson.set_function("int32", int32);
llbson.set_function("int64", int64);
llbson.set_function("pairs", pairs);
Expand Down

0 comments on commit ac203fc

Please sign in to comment.