moped icon indicating copy to clipboard operation
moped copied to clipboard

moped 1.5 doesn't work correctly on big-endian systems

Open bryanpkc opened this issue 10 years ago • 1 comments

lib/moped/bson.rb specifies the ways in which BSON fields are packed, but they currently use native endianness, which leads to errors on a big-endian system because the encoding for BSON fields are in little-endian byte order. The following patch fixes the problem.

diff --git a/lib/moped/bson.rb b/lib/moped/bson.rb
index 2136aa2..5aca1c1 100644
--- a/lib/moped/bson.rb
+++ b/lib/moped/bson.rb
@@ -16,8 +16,8 @@ module Moped

     EOD = NULL_BYTE = "\u0000".freeze

-    INT32_PACK = 'l'.freeze
-    INT64_PACK = 'q'.freeze
+    INT32_PACK = "l<".freeze
+    INT64_PACK = 'q<'.freeze
     FLOAT_PACK = 'E'.freeze

     START_LENGTH = [0].pack(INT32_PACK).freeze

bryanpkc avatar Sep 23 '15 15:09 bryanpkc

I can confirm this is an issue on BE systems [1] and the patch appears to fix the issues.

https://bugzilla.redhat.com/show_bug.cgi?id=1481611

voxik avatar Aug 16 '17 13:08 voxik