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