Class: Resolv::DNS::Message::MessageEncoder
- Inherits:
-
Object
- Object
- Resolv::DNS::Message::MessageEncoder
- Defined in:
- lib/logmerge/resolv.rb
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ MessageEncoder
constructor
A new instance of MessageEncoder.
- #put_bytes(d) ⇒ Object
- #put_label(d) ⇒ Object
- #put_labels(d) ⇒ Object
- #put_length16 ⇒ Object
- #put_name(d) ⇒ Object
- #put_pack(template, *d) ⇒ Object
- #put_string(d) ⇒ Object
- #put_string_list(ds) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ MessageEncoder
Returns a new instance of MessageEncoder.
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_length16 ⇒ Object
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_s ⇒ Object
1166 1167 1168 |
# File 'lib/logmerge/resolv.rb', line 1166 def to_s return @data end |