Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2334

JRuby change buffer to use read/write pointers instead of flipping

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: BSON, JRuby
    • None
    • Minor Change

      The way JRuby currently reads and writes from the Java ByteBuffer is by using a flipping method, wherein on any read or write, the ByteBuffer is flipped.

      The problem with this is when reading and writing multiple times from the buffer, the correct values are not returned. Take the following example:

      buffer = BSON::ByteBuffer.new
      buffer.put_int32(3)
      buffer.put_int32(2)
      puts buffer.get_int32
      buffer.put_int32(1)
      puts buffer.get_int32
      puts buffer.get_int32
      Results on master branch:
      MRI:
      3
      2
      1
      JRUBY:
      3
      3
      3
      

      Here there are three numbers added to the buffer, and while MRI reads them out in order, JRuby only returns the first number. 

      My proposed solution is to no longer use the flipping method for reading and writing from the buffer, rather to use the read/write position pointers that are already there to index into the buffer and get/write the value from/into the correct location.

            Assignee:
            Unassigned Unassigned
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: