Minor refactor

This commit is contained in:
Omar Roth 2019-09-18 19:47:17 -04:00
parent d70b15c946
commit 5b60fe7736
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2

View File

@ -55,7 +55,7 @@ struct VarLong
end end
end end
class ProtoBuf struct ProtoBuf::Any
enum Tag enum Tag
VarInt = 0 VarInt = 0
Bit64 = 1 Bit64 = 1
@ -63,9 +63,8 @@ class ProtoBuf
Bit32 = 5 Bit32 = 5
end end
struct Any
alias Type = Int64 | alias Type = Int64 |
Array(UInt8) | Bytes |
String | String |
Hash(Int32, Type) Hash(Int32, Type)
@ -93,7 +92,6 @@ class ProtoBuf
when Tag::Bit64 when Tag::Bit64
value = Bytes.new(8) value = Bytes.new(8)
io.read_fully(value) io.read_fully(value)
value = value.to_a
when Tag::LengthDelimited when Tag::LengthDelimited
bytes = Bytes.new(io.read_bytes(VarLong)) bytes = Bytes.new(io.read_bytes(VarLong))
io.read_fully(bytes) io.read_fully(bytes)
@ -110,7 +108,7 @@ class ProtoBuf
begin begin
value = from_io(IO::Memory.new(bytes)).raw value = from_io(IO::Memory.new(bytes)).raw
rescue ex rescue ex
value = bytes.to_a value = bytes
end end
end end
end end
@ -118,7 +116,6 @@ class ProtoBuf
when Tag::Bit32 when Tag::Bit32
value = Bytes.new(4) value = Bytes.new(4)
io.read_fully(value) io.read_fully(value)
value = value.to_a
else else
break if ignore_exceptions break if ignore_exceptions
raise "Invalid type #{type}" raise "Invalid type #{type}"
@ -140,7 +137,6 @@ class ProtoBuf
end end
end end
end end
end
enum InputType enum InputType
Base64 Base64