Knot::Protocol#snd supports strings as key, too (calls to_sym)

This commit is contained in:
Denis Knauf 2022-12-13 23:38:43 +01:00
parent 59db51d2ed
commit 12639f766c

View file

@ -183,21 +183,13 @@ class Knot::Protocol
def snd sock: nil, **data
rsock = sock || @sock
#s = ''.b
#sock = StringIO.new s
#sock.write [1].pack( 'c')
data = Hash[ *data.map {|k,v| [k.to_sym, v]}.flatten]
data[:flags] ||= ''
ds =
Idx.
select {|n| data[n.to_sym] }.
map {|n| v = data[n.to_sym].to_s.b; [n.to_i, v.size, v ] }
select {|n| p [n.to_sym, data[n.to_sym]]; data[n.to_sym] }.
map {|n| v = data[n.to_sym].to_s.b; [n.to_i, v.size, v] }
s = [Types[:data].to_i, ds, Types[:block].to_i].flatten.pack( "c #{'c na*'*ds.length} c").b
#Idx.each do |n|
# v = data[n.to_sym]&.to_s&.b
# sock.write [n.to_i, v.size, v].pack( 'c na*') if v
#end
#sock.write [3].pack( 'c')
#sock.flush
if 0 >= @logger.sev_threshold
@logger.debug "send data #{data.inspect}"
@logger.debug "send raw #{s.inspect}"