Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal
- include TxtRPC::TxtRPCObject
- extend TxtRPC::Serialization
- extend BuildPattern
- rpc_property 1, name, String
- rpc_property 2, max_speed, Int64
- def initialize
- @name = ""
- @max_speed = 0
- end
- end
- class Person
- include TxtRPC::TxtRPCObject
- extend TxtRPC::Serialization
- extend BuildPattern
- rpc_property 5, age, Int64
- rpc_property 1, name, String
- rpc_property 2, left_handed, Bool
- rpc_property 3, emails, Array(String)
- rpc_property 4, nicknames, Set(String)
- rpc_property 6, fav_numbers, Set(Int64)
- rpc_property 7, jobs, Hash(Int64, String)
- # Intentionally skip 8, to simulate a field being deprecated
- rpc_property 9, pets, Hash(Int64, Animal) # key = year adopted
- def initialize
- @name = ""
- @age = 0
- @left_handed = false
- @emails = Array(String).new
- @nicknames = Set(String).new
- @fav_numbers = Set(Int64).new
- @jobs = Hash(Int64, String).new
- @pets = Hash(Int64, Animal).new
- end
- end
- it "serializes RPC objects" do
- p = Person.new
- p.name = "Thor"
- p.age = 1500_i64
- p.emails << "thor@asgard.com"
- p.emails << "son_of_odin@asgard.com"
- p.fav_numbers << 7
- p.fav_numbers << 18
- p.fav_numbers << 1
- p.nicknames << "God of Thunder"
- p.pets[2000] = Animal.build do |x|
- x.name = "Appa"
- x.max_speed = 200
- end
- s = serialize(p)
- s.should start_with("O8")
- s.should contain("i5\ni1500\n")
- s.should contain("i1\ns4\nThor\n")
- s.should contain("i2\nb0\n")
- s.should contain("A2\ns15\nthor@asgard.com\ns22\nson_of_odin@asgard.com\n")
- s.should contain("S3\ni7\ni18\ni1")
- s.should contain("S1\ns14\nGod of Thunder\n")
- s.should contain("M1\ni2000\nO2\ni1\ns4\nAppa\ni2\ni200\n")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement