lib/aerospike/cluster/partition_tokenizer_new.rb
def update_partition(nmap, node)
      amap = nil

      beginning = @offset
      copied = false

      while @offset < @length
        if @buffer[@offset] == ':'
          # Parse namespace.
          namespace = @buffer[beginning...@offset].strip

          if namespace.length <= 0 || namespace.length >= 32
            response = get_truncated_response
            raise Aerospike::Exceptions::Parse.new(
              "Invalid partition namespace #{namespace}. Response=#{response}"
            )
          end

          @offset+=1
          beginning = @offset

          # Parse partition id.
          while @offset < @length
            b = @buffer[@offset]

            break if b == ';' || b == "\n"
            @offset+=1
          end

          if @offset == beginning
            response = get_truncated_response

            raise Aerospike::Exceptions::Parse.new(
              "Empty partition id for namespace #{namespace}. Response=#{response}"
            )
          end

          node_array = nmap[namespace]

          if !node_array
            if !copied
              # Make shallow copy of map.
              amap = {}
              nmap.each {|k, v| amap[k] = Atomic.new(v)}
              copied = true
            end

            node_array = Atomic.new(Array.new(Aerospike::Node::PARTITIONS))
            amap[namespace] = node_array
          end

          bit_map_length = @offset - beginning
          restore_buffer = Base64.strict_decode64(@buffer[beginning, bit_map_length])
          i = 0
          while i < Aerospike::Node::PARTITIONS
            if (restore_buffer[i>>3].ord & (0x80 >> (i & 7))) != 0
              # Logger.Info("Map: `" + namespace + "`," + strconv.Itoa(i) + "," + node.String)
              node_array.update{|v| v[i] = node; v}
            end
            i = i.succ
          end

          @offset+=1
          beginning = @offset
        else
          @offset+=1
        end
      end

      copied ? amap : nil
    end
def update_partition(nmap, node)
      amap = nil

      beginning = @offset
      copied = false

      while @offset < @length
        if @buffer[@offset] == ':'
          # Parse namespace.
          namespace = @buffer[beginning...@offset].strip

          if namespace.length <= 0 || namespace.length >= 32
            response = get_truncated_response
            raise Aerospike::Exceptions::Parse.new(
              "Invalid partition namespace #{namespace}. Response=#{response}"
            )
          end

          @offset+=1
          beginning = @offset

          # Parse partition id.
          while @offset < @length
            b = @buffer[@offset]

            break if b == ';' || b == "\n"
            @offset+=1
          end

          if @offset == beginning
            response = get_truncated_response

            raise Aerospike::Exceptions::Parse.new(
              "Empty partition id for namespace #{namespace}. Response=#{response}"
            )
          end

          node_array = nmap[namespace]

          if !node_array
            if !copied
              # Make shallow copy of map.
              amap = {}
              nmap.each {|k, v| amap[k] = Atomic.new(v)}
              copied = true
            end

            node_array = Atomic.new(Array.new(Aerospike::Node::PARTITIONS))
            amap[namespace] = node_array
          end

          bit_map_length = @offset - beginning
          restore_buffer = Base64.strict_decode64(@buffer[beginning, bit_map_length])
          i = 0
          while i < Aerospike::Node::PARTITIONS
            if (restore_buffer[i>>3].ord & (0x80 >> (i & 7))) != 0
              # Logger.Info("Map: `" + namespace + "`," + strconv.Itoa(i) + "," + node.String)
              node_array.update{|v| v[i] = node; v}
            end
            i = i.succ
          end

          @offset+=1
          beginning = @offset
        else
          @offset+=1
        end
      end

      copied ? amap : nil
    end
:nodoc: