Class: Resolv::DNS::Message::MessageEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/logmerge/resolv.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ MessageEncoder

Returns a new instance of MessageEncoder.

Yields:

  • (_self)

Yield Parameters:



1160
1161
1162
1163
1164
# File 'lib/logmerge/resolv.rb', line 1160

def initialize
  @data = ''
  @names = {}
  yield self
end

Instance Method Details

#put_bytes(d) ⇒ Object



1170
1171
1172
# File 'lib/logmerge/resolv.rb', line 1170

def put_bytes(d)
  @data << d
end

#put_label(d) ⇒ Object



1216
1217
1218
# File 'lib/logmerge/resolv.rb', line 1216

def put_label(d)
  self.put_string(d.string)
end

#put_labels(d) ⇒ Object



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/logmerge/resolv.rb', line 1202

def put_labels(d)
  d.each_index {|i|
    domain = d[i..-1]
    if idx = @names[domain]
      self.put_pack("n", 0xc000 | idx)
      return
    else
      @names[domain] = @data.length
      self.put_label(d[i])
    end
  }
  @data << "\0"
end

#put_length16Object



1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/logmerge/resolv.rb', line 1178

def put_length16
  length_index = @data.length
  @data << "\0\0"
  data_start = @data.length
  yield
  data_end = @data.length
  @data[length_index, 2] = [data_end - data_start].pack("n")
end

#put_name(d) ⇒ Object



1198
1199
1200
# File 'lib/logmerge/resolv.rb', line 1198

def put_name(d)
  put_labels(d.to_a)
end

#put_pack(template, *d) ⇒ Object



1174
1175
1176
# File 'lib/logmerge/resolv.rb', line 1174

def put_pack(template, *d)
  @data << d.pack(template)
end

#put_string(d) ⇒ Object



1187
1188
1189
1190
# File 'lib/logmerge/resolv.rb', line 1187

def put_string(d)
  self.put_pack("C", d.length)
  @data << d
end

#put_string_list(ds) ⇒ Object



1192
1193
1194
1195
1196
# File 'lib/logmerge/resolv.rb', line 1192

def put_string_list(ds)
  ds.each {|d|
    self.put_string(d)
  }
end

#to_sObject



1166
1167
1168
# File 'lib/logmerge/resolv.rb', line 1166

def to_s
  return @data
end