Skip to content

Commit

Permalink
修复bsonBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed May 23, 2024
1 parent f65746b commit be039cc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions extend/lbson/src/bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ namespace lbson {
}

int binary(lua_State* L) {
m_buffer.clean();
size_t data_len = 0;
const char* value = lua_tolstring(L, 1, &data_len);
luaL_Buffer b;
luaL_buffinit(L, &b);
luaL_addchar(&b, 0);
luaL_addchar(&b, (uint8_t)bson_type::BSON_BINARY);
luaL_addchar(&b, 0);
luaL_addlstring(&b, value, data_len);
luaL_pushresult(&b);
m_buffer.write<uint8_t>(0);
m_buffer.write<uint8_t>((uint8_t)bson_type::BSON_BINARY);
m_buffer.write<uint8_t>(0); //subtype
m_buffer.write<int32_t>(data_len);
m_buffer.push_data((uint8_t*)value, data_len);
lua_pushlstring(L, (const char*)m_buffer.head(), m_buffer.size());
return 1;
}

Expand Down Expand Up @@ -545,12 +545,13 @@ namespace lbson {
break;
case bson_type::BSON_BINARY: {
lua_createtable(L, 0, 4);
int32_t len = read_val<int32_t>(L, slice);
lua_pushinteger(L, (uint32_t)bt);
lua_setfield(L, -2, "__type");
lua_pushinteger(L, read_val<uint8_t>(L, slice));
lua_setfield(L, -2, "subtype");
const char* s = read_bytes(L, slice, sz);
lua_pushlstring(L, s, sz);
const char* s = read_bytes(L, slice, len);
lua_pushlstring(L, s, len);
lua_setfield(L, -2, "binray");
}
break;
Expand Down Expand Up @@ -639,7 +640,7 @@ namespace lbson {
m_bson->unpack_dict(L, m_slice, false);
} catch (const exception& e){
lua_settop(L, otop);
throw e;
throw lua_exception(e.what());
}
return lua_gettop(L) - otop;
}
Expand Down

0 comments on commit be039cc

Please sign in to comment.