Permalink
Browse files

can read object counts

  • Loading branch information...
1 parent 9608176 commit bf4ddf83dd59815779c864b32a922415c670ad5a @tenderlove committed Nov 17, 2010
Showing with 44 additions and 5 deletions.
  1. +3 −1 lib/orient.rb
  2. +41 −4 lib/orient/connections/binary.rb
View
@@ -7,5 +7,7 @@ module Orient
if $0 == __FILE__
conn = Orient::Connections::Binary.new 'localhost'
clusters = conn.db_open 'local:demo', 'admin', 'admin'
- conn.datacluster_count clusters.first
+ p conn.count clusters.find { |c| c.name == 'default' }
+ #conn.datacluster_count clusters
+ #conn.datacluster_datarange clusters.first
end
@@ -11,7 +11,45 @@ def initialize remote_host, port = 2424, lhost = nil, lport = nil
@tx = 0
end
- def datacluster_count cluster
+ def count cluster
+ header = [ 40, @tx ]
+ header = header.pack('cN')
+ name = cluster.name
+ str = [
+ [ name.bytesize, name ],
+ ]
+ str = str.map { |tuple| [tuple.first].pack('N') + tuple.last }.join
+ @socket.write(header + str)
+ response, txid = @socket.read(5).unpack('cN')
+ high, low = @socket.read(8).unpack('NN')
+ (high << 32) + low
+ end
+
+ def datacluster_datarange cluster
+ header = [ 13, @tx ]
+ header = header.pack('cN')
+ packet = [cluster.id].pack 'n'
+ @socket.write(header + packet)
+
+ response, txid = @socket.read(5).unpack('cN')
+ raise unless response == 0
+
+ @tx += 1
+ @socket.read(8).unpack('NN')
+ end
+
+ def datacluster_count clusters
+ header = [ 12, @tx ]
+ header = header.pack('cN')
+ packet = [ clusters.length ] + clusters.map { |x| x.id }
+ packet = packet.pack("n#{clusters.length + 1}")
+ @socket.write(header + packet)
+
+ @tx += 1
+ response, txid = @socket.read(5).unpack('cN')
+ raise unless response == 0
+
+ @socket.read(4).unpack('N').first
end
def db_open db, user, pass
@@ -29,11 +67,10 @@ def db_open db, user, pass
@socket.write(header + str)
@tx += 1
- response = @socket.read(1).unpack('c').first
-
+ response, txid = @socket.read(5).unpack('cN')
raise unless response == 0
- txid, connection_id, cluster_count = @socket.read(12).unpack('N3')
+ connection_id, cluster_count = @socket.read(8).unpack('NN')
clusters = []
cluster_count.times do

0 comments on commit bf4ddf8

Please sign in to comment.