Skip to content

Commit a0da881

Browse files
authored
Allow storing unknown enum values (#209)
1 parent 491d4c8 commit a0da881

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/codec/decode.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
decode(d::AbstractProtoDecoder, ::Type{Bool}) = Bool(read(d.io, UInt8))
2727
function decode(d::AbstractProtoDecoder, ::Type{T}) where {T <: Union{Enum{Int32},Enum{UInt32}}}
2828
val = vbyte_decode(d.io, UInt32)
29-
return val in keys(Base.Enums.namemap(T)) ? T(val) : T(0)
29+
return Core.bitcast(T, reinterpret(Int32, val))
3030
end
3131
decode(d::AbstractProtoDecoder, ::Type{T}) where {T <: Union{Float64,Float32}} = read(d.io, T)
3232
function decode!(d::AbstractProtoDecoder, buffer::Dict{K,V}) where {K,V<:_ScalarTypesEnum}

test/test_decode.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ end
298298
@testset "enum" begin
299299
test_decode([0x02], TestEnum.C)
300300
end
301+
302+
@testset "unknown enum member" begin
303+
test_decode([0x10], Core.bitcast(TestEnum.T, Int32(0x10)))
304+
end
301305
end
302306

303307
@testset "fixed" begin

0 commit comments

Comments
 (0)