resolv.rb: byte buffer
* lib/resolv.rb (Resolv::DNS::Message::MessageDecoder): treat the data as a byte buffer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2b2450ba4b
commit
8b8505d239
@ -1521,12 +1521,12 @@ class Resolv
|
|||||||
def initialize(data)
|
def initialize(data)
|
||||||
@data = data
|
@data = data
|
||||||
@index = 0
|
@index = 0
|
||||||
@limit = data.length
|
@limit = data.bytesize
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"\#<#{self.class}: #{@data[0, @index].inspect} #{@data[@index..-1].inspect}>"
|
"\#<#{self.class}: #{@data.byteslice(0, @index).inspect} #{@data.byteslice(@index..-1).inspect}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_length16
|
def get_length16
|
||||||
@ -1545,7 +1545,7 @@ class Resolv
|
|||||||
|
|
||||||
def get_bytes(len = @limit - @index)
|
def get_bytes(len = @limit - @index)
|
||||||
raise DecodeError.new("limit exceeded") if @limit < @index + len
|
raise DecodeError.new("limit exceeded") if @limit < @index + len
|
||||||
d = @data[@index, len]
|
d = @data.byteslice(@index, len)
|
||||||
@index += len
|
@index += len
|
||||||
return d
|
return d
|
||||||
end
|
end
|
||||||
@ -1573,9 +1573,9 @@ class Resolv
|
|||||||
|
|
||||||
def get_string
|
def get_string
|
||||||
raise DecodeError.new("limit exceeded") if @limit <= @index
|
raise DecodeError.new("limit exceeded") if @limit <= @index
|
||||||
len = @data[@index].ord
|
len = @data.getbyte(@index)
|
||||||
raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
|
raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
|
||||||
d = @data[@index + 1, len]
|
d = @data.byteslice(@index + 1, len)
|
||||||
@index += 1 + len
|
@index += 1 + len
|
||||||
return d
|
return d
|
||||||
end
|
end
|
||||||
@ -1598,7 +1598,7 @@ class Resolv
|
|||||||
d = []
|
d = []
|
||||||
while true
|
while true
|
||||||
raise DecodeError.new("limit exceeded") if @limit <= @index
|
raise DecodeError.new("limit exceeded") if @limit <= @index
|
||||||
case @data[@index].ord
|
case @data.getbyte(@index)
|
||||||
when 0
|
when 0
|
||||||
@index += 1
|
@index += 1
|
||||||
if save_index
|
if save_index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user