Class: GitDB::Protocol
- Inherits:
-
Object
- Object
- GitDB::Protocol
- Defined in:
- lib/git-db/protocol.rb
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
-
#flush ⇒ Object
commands ##################################################################.
-
#initialize(io = nil) ⇒ Protocol
constructor
A new instance of Protocol.
- #read_command ⇒ Object
-
#read_pack ⇒ Object
packs #####################################################################.
- #write(data) ⇒ Object
- #write_command(command) ⇒ Object
- #write_eof ⇒ Object
- #write_pack(entries) ⇒ Object
Constructor Details
#initialize(io = nil) ⇒ Protocol
Returns a new instance of Protocol.
6 7 8 9 10 11 12 13 14 |
# File 'lib/git-db/protocol.rb', line 6 def initialize(io=nil) if io @reader = io @writer = io else @reader = STDIN @writer = STDOUT end end |
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
3 4 5 |
# File 'lib/git-db/protocol.rb', line 3 def reader @reader end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
4 5 6 |
# File 'lib/git-db/protocol.rb', line 4 def writer @writer end |
Instance Method Details
#flush ⇒ Object
commands ##################################################################
18 19 20 |
# File 'lib/git-db/protocol.rb', line 18 def flush writer.flush end |
#read_command ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git-db/protocol.rb', line 22 def read_command length = reader.read(4) return nil unless length length = length.to_i(16) - 4 if (length == -4) GitDB.log('GOT EOF') return end data = reader.read(length) GitDB.log("GOT DATA: #{data.inspect}") data end |
#read_pack ⇒ Object
packs #####################################################################
55 56 57 |
# File 'lib/git-db/protocol.rb', line 55 def read_pack GitDB::Pack.new(reader).read end |
#write(data) ⇒ Object
42 43 44 45 |
# File 'lib/git-db/protocol.rb', line 42 def write(data) writer.write data writer.flush end |
#write_command(command) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/git-db/protocol.rb', line 35 def write_command(command) raw_command = encode_command(command) GitDB.log("WWRITING COMMAND: #{raw_command.inspect}") writer.print raw_command writer.flush end |
#write_eof ⇒ Object
47 48 49 50 51 |
# File 'lib/git-db/protocol.rb', line 47 def write_eof #GitDB.log("WRITING EOF") writer.print '0000' writer.flush end |
#write_pack(entries) ⇒ Object
59 60 61 |
# File 'lib/git-db/protocol.rb', line 59 def write_pack(entries) GitDB::Pack.new(writer).write(entries) end |