Skip to content

Commit c5e2a3f

Browse files
committed
Added a decode implementation as well
1 parent 022c3b8 commit c5e2a3f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/hparams.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ function PB.Codecs._encoded_size(d::Dict{String,HValue}, i::Int)
103103
end, +, d, init=0)
104104
end
105105

106+
function PB.Codecs.decode!(d::ProtoDecoder, buffer::Dict{String,HValue})
107+
len = PB.Codecs.vbyte_decode(d.io, UInt32)
108+
endpos = position(d.io) + len
109+
while position(d.io) < endpos
110+
pair_field_number, pair_wire_type = PB.Codecs.decode_tag(d)
111+
pair_len = PB.Codecs.vbyte_decode(d.io, UInt32)
112+
pair_end_pos = position(d.io) + pair_len
113+
field_number, wire_type = PB.Codecs.decode_tag(d)
114+
key = PB.Codecs.decode(d, K)
115+
field_number, wire_type = PB.Codecs.decode_tag(d)
116+
val = PB.Codecs.decode(d, Ref{V})
117+
@assert position(d.io) == pair_end_pos
118+
buffer[key] = val
119+
end
120+
@assert position(d.io) == endpos
121+
nothing
122+
end
106123

107124
"""
108125
write_hparams!(logger::TBLogger, hparams::Dict{String, Any}, metrics::AbstractArray{String})

0 commit comments

Comments
 (0)