Skip to content

Commit 627db33

Browse files
committed
Add an overload for writing the dictionary
1 parent 7e5b00c commit 627db33

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/hparams.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import .tensorboard_plugin_hparams.hparams: var"#DataType" as HParamDataType, DatasetType as HDatasetType
22
import .tensorboard_plugin_hparams.google.protobuf: ListValue as HListValue, Value as HValue
33
import .tensorboard_plugin_hparams.hparams as HP
4+
import ProtoBuf as PB
45

56
struct HParamRealDomain
67
min_value::Float64
@@ -79,6 +80,19 @@ function encode_bytes(content::HP.HParamsPluginData)
7980
return take!(data)
8081
end
8182

83+
# Overload the dictionary encoder
84+
function PB.encode(e::ProtoEncoder, i::Int, x::Dict{String,HValue})
85+
PB.Codecs.encode_tag(e, i, PB.Codecs.LENGTH_DELIMITED)
86+
PB.Codecs.vbyte_encode(e.io, UInt32(PB.Codecs._encoded_size(x)))
87+
88+
for (k, v) in x
89+
PB.Codecs.encode(e, 1, k)
90+
PB.Codecs.encode(e, 2, v)
91+
end
92+
return nothing
93+
end
94+
95+
8296
"""
8397
write_hparams!(logger::TBLogger, hparams::Dict{String, Any}, metrics::AbstractArray{String})
8498

0 commit comments

Comments
 (0)