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 34 35 36 37 38 |
# File 'lib/git-db/protocol.rb', line 22 def read_command # length is stored in the first 4 bytes length = reader.read(4) return nil unless length # length is stored as hex, convert back to decimal and return if it's 0 length = length.to_i(16) return if length.zero? # length includes the 4 bytes of the length itself, subtract for data length -= 4 # read and return the data data = reader.read(length) GitDB.log("RECEIVED COMMAND: #{data.inspect}") data end |
#read_pack ⇒ Object
packs #####################################################################
62 63 64 |
# File 'lib/git-db/protocol.rb', line 62 def read_pack GitDB::Pack.new(reader).read end |
#write(data) ⇒ Object
50 51 52 53 |
# File 'lib/git-db/protocol.rb', line 50 def write(data) writer.write data writer.flush end |
#write_command(command) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/git-db/protocol.rb', line 40 def write_command(command) # output the length writer.print length_as_hex(command) # output the data GitDB.log("SENDING COMMAND: #{command.inspect}") writer.print command writer.flush end |
#write_eof ⇒ Object
55 56 57 58 |
# File 'lib/git-db/protocol.rb', line 55 def write_eof writer.print '0000' writer.flush end |