34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/zero_formatter/serializer.rb', line 34
def dump(value)
last_index = value.class.fields.last[:index]
= []
= "".force_encoding("ASCII-8bit")
data = "".force_encoding("ASCII-8bit")
= 4 + 4 + (last_index+1)*4
value.class.fields.each do |field|
[field[:index]] = + data.bytesize
v = value.send(field[:name])
if field[:options][:nullable]
data << Utils.write_u1(v.nil? ? 0 : 1)
end
data << get_serializer(field[:type]).serialize(v)
end
.each do |h|
<< Utils.write_s4(h || -1)
end
data_size = + data.bytesize
response = "".force_encoding("ASCII-8bit")
response << Utils.write_s4(data_size)
response << Utils.write_s4(last_index)
response <<
response << data
response
end
|