Sha256: 2c7ccddad7553c225f81b14827a95d8752a7b877922408acaeabf8e259ce68f0
Contents?: true
Size: 1.31 KB
Versions: 6
Compression:
Stored size: 1.31 KB
Contents
require 'test/unit' require 'test/proto/packed.pb' class PackedFieldTest < Test::Unit::TestCase def test_packed_field values = [1, 1_000, 10_000, 1_000_000, 1_000_000_000] # encode message = Test::PackedField::Message.new message.a = values message.b = values expected = '' serialized_string = nil assert_nothing_raised { serialized_string = message.serialize_to_string } value = values.map {|v| Protobuf::Field::VarintField.encode(v) }.join expected << Protobuf::Field::VarintField.encode((1 << 3) | 2) # tag=1, wire_type=2 (length-delimited) expected << Protobuf::Field::VarintField.encode(value.size) expected << value value = values.pack('V*') expected << Protobuf::Field::VarintField.encode((2 << 3) | 2) # tag=2, wire_type=2 (length-delimited) expected << Protobuf::Field::VarintField.encode(value.size) expected << value assert_equal(expected, serialized_string) # decode message2 = Test::PackedField::Message.new assert_nothing_raised { message2.parse_from_string(serialized_string) } values.each_with_index do |val, n| assert_equal(val, message.a[n]) assert_equal(val, message.b[n]) end end def test_empty_packed_field message = Test::PackedField::Message.new assert_equal('', message.to_s) end end
Version data entries
6 entries across 6 versions & 1 rubygems