Fix size for string encoding

This commit is contained in:
Omar Roth 2019-09-20 17:11:08 -04:00
parent b08f41bd3c
commit ce002cbd3e
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2

View File

@ -214,22 +214,22 @@ struct ProtoBuf::Any
when "float64" when "float64"
value.as_f32.to_f64.to_io(io, IO::ByteFormat::LittleEndian) value.as_f32.to_f64.to_io(io, IO::ByteFormat::LittleEndian)
when "string" when "string"
VarLong.to_io(io, value.as_s.size.to_i64) VarLong.to_io(io, value.as_s.bytesize.to_i64)
value.as_s.to_s(io) io.print value.as_s
when "base64" when "base64"
buffer = IO::Memory.new buffer = IO::Memory.new
from_json(value, buffer) from_json(value, buffer)
buffer.rewind buffer.rewind
buffer = Base64.urlsafe_encode(buffer, padding: false) buffer = Base64.urlsafe_encode(buffer, padding: false)
VarLong.to_io(io, buffer.size.to_i64) VarLong.to_io(io, buffer.bytesize.to_i64)
buffer.to_s(io) buffer.to_s(io)
when "embedded" when "embedded"
buffer = IO::Memory.new buffer = IO::Memory.new
from_json(value, buffer) from_json(value, buffer)
buffer.rewind buffer.rewind
VarLong.to_io(io, buffer.size.to_i64) VarLong.to_io(io, buffer.bytesize.to_i64)
IO.copy(buffer, io) IO.copy(buffer, io)
when "bytes" when "bytes"
VarLong.to_io(io, value.size.to_i64) VarLong.to_io(io, value.size.to_i64)