From 0f64e909fa10784f1a8b6d6b9fea634af76a75d2 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Wed, 11 Jun 2014 15:11:18 +0800 Subject: [PATCH] big-endian encoding bson objectid --- HISTORY.md | 6 ++++++ lualib-src/lua-bson.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e498068a..828a8a00 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,9 @@ +Dev version +----------- +* Bugfix: lua mongo driver . Hold reply string before decode bson data. +* More check in bson decoding. +* Use big-endian for encoding bson objectid. + v0.3.0 (2014-6-2) ----------- * Add cluster support diff --git a/lualib-src/lua-bson.c b/lualib-src/lua-bson.c index 1799d7bf..07fb77e2 100644 --- a/lualib-src/lua-bson.c +++ b/lualib-src/lua-bson.c @@ -1149,14 +1149,14 @@ lobjectid(lua_State *L) { } } else { time_t ti = time(NULL); - oid[2] = ti & 0xff; - oid[3] = (ti>>8) & 0xff; - oid[4] = (ti>>16) & 0xff; - oid[5] = (ti>>24) & 0xff; + oid[2] = (ti>>24) & 0xff; + oid[3] = (ti>>16) & 0xff; + oid[4] = (ti>>8) & 0xff; + oid[5] = ti & 0xff; memcpy(oid+6 , oid_header, 5); - oid[11] = oid_counter & 0xff; + oid[11] = (oid_counter>>16) & 0xff; oid[12] = (oid_counter>>8) & 0xff; - oid[13] = (oid_counter>>16) & 0xff; + oid[13] = oid_counter & 0xff; ++oid_counter; } lua_pushlstring( L, (const char *)oid, 14);