Class: GitDB::Protocol
- Inherits:
-
Object
- Object
- GitDB::Protocol
- Defined in:
- lib/git-db/protocol.rb
Instance Attribute Summary (collapse)
-
- (Object) reader
readonly
Returns the value of attribute reader.
-
- (Object) writer
readonly
Returns the value of attribute writer.
Instance Method Summary (collapse)
-
- (Object) flush
commands ##################################################################.
-
- (Protocol) initialize(io = nil)
constructor
A new instance of Protocol.
- - (Object) read_command
-
- (Object) read_pack
packs #####################################################################.
- - (Object) write(data)
- - (Object) write_command(command)
- - (Object) write_eof
- - (Object) write_pack(entries)
Constructor Details
- (Protocol) initialize(io = nil)
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
- (Object) reader (readonly)
Returns the value of attribute reader
3 4 5 |
# File 'lib/git-db/protocol.rb', line 3 def reader @reader end |
- (Object) writer (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
- (Object) flush
commands ##################################################################
18 19 20 |
# File 'lib/git-db/protocol.rb', line 18 def flush writer.flush end |
- (Object) read_command
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 |
- (Object) read_pack
packs #####################################################################
62 63 64 |
# File 'lib/git-db/protocol.rb', line 62 def read_pack GitDB::Pack.new(reader).read end |
- (Object) write(data)
50 51 52 53 |
# File 'lib/git-db/protocol.rb', line 50 def write(data) writer.write data writer.flush end |
- (Object) write_command(command)
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 |
- (Object) write_eof
55 56 57 58 |
# File 'lib/git-db/protocol.rb', line 55 def write_eof writer.print '0000' writer.flush end |
- (Object) write_pack(entries)
66 67 68 |
# File 'lib/git-db/protocol.rb', line 66 def write_pack(entries) GitDB::Pack.new(writer).write(entries) end |