mirror of
https://gitea.invidious.io/iv-org/protodec.git
synced 2024-08-15 00:43:18 +00:00
Fix overwriting fields
This commit is contained in:
parent
89b2ee0d29
commit
bfe9627836
1 changed files with 7 additions and 5 deletions
|
@ -52,7 +52,7 @@ struct ProtoBuf::Any
|
||||||
Float64 |
|
Float64 |
|
||||||
Array(UInt8) |
|
Array(UInt8) |
|
||||||
String |
|
String |
|
||||||
Hash(Int32, Type)
|
Hash(String, Type)
|
||||||
|
|
||||||
getter raw : Type
|
getter raw : Type
|
||||||
|
|
||||||
|
@ -73,7 +73,8 @@ struct ProtoBuf::Any
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_io(io : IO, format = IO::ByteFormat::NetworkEndian, ignore_exceptions = false)
|
def self.from_io(io : IO, format = IO::ByteFormat::NetworkEndian, ignore_exceptions = false)
|
||||||
item = new({} of Int32 => Type)
|
item = new({} of String => Type)
|
||||||
|
index = 0
|
||||||
|
|
||||||
begin
|
begin
|
||||||
until io.pos == io.size
|
until io.pos == io.size
|
||||||
|
@ -136,7 +137,8 @@ struct ProtoBuf::Any
|
||||||
raise "Invalid type #{type}"
|
raise "Invalid type #{type}"
|
||||||
end
|
end
|
||||||
|
|
||||||
item[field] = value.as(Type)
|
item["#{field}:#{index}"] = value.as(Type)
|
||||||
|
index += 1
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue ex
|
||||||
if !ignore_exceptions
|
if !ignore_exceptions
|
||||||
|
@ -147,12 +149,12 @@ struct ProtoBuf::Any
|
||||||
item
|
item
|
||||||
end
|
end
|
||||||
|
|
||||||
def []=(key : Int32, value : Type)
|
def []=(key : String, value : Type)
|
||||||
case object = @raw
|
case object = @raw
|
||||||
when Hash
|
when Hash
|
||||||
object[key] = value
|
object[key] = value
|
||||||
else
|
else
|
||||||
raise "Expected Hash for #[]=(key : Int32, value : Type), not #{object.class}"
|
raise "Expected Hash for #[]=(key : String, value : Type), not #{object.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue