summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-08-12 19:23:26 -0700
committerJoshua Haberman <jhaberman@gmail.com>2018-08-12 19:23:26 -0700
commitc8f6a27e6b27ed5d51cf6c8da5ec080b9952fa99 (patch)
tree8d9e160dcb6f52f530a00868f342ab08121d1684 /tests
parentb0a6602fc8fddf71ac959d43b4cd82707e6235b9 (diff)
Enforced that upb_msg lives in an Arena only, and other simplifying.
upb_msg was trying to be general enough that it could either live in an arena or be allocated with malloc()/free(). This was too much complexity for too little benefit. We should commit to just saying that upb_msg is arena-only. I also ripped out the code to glue upb_msg to the existing handlers-based encoder/decoder. upb_msg has its own, small, simple encoder/decoder. I'm trying to whittle down upb_msg to a small and simple core. I updated the Lua extension for these changes. Lua needs some more work to properly create arenas per message. For now I just created a single global arena.
Diffstat (limited to 'tests')
-rw-r--r--tests/bindings/lua/test_upb.pb.lua25
1 files changed, 7 insertions, 18 deletions
diff --git a/tests/bindings/lua/test_upb.pb.lua b/tests/bindings/lua/test_upb.pb.lua
index 106dc55..752a736 100644
--- a/tests/bindings/lua/test_upb.pb.lua
+++ b/tests/bindings/lua/test_upb.pb.lua
@@ -27,25 +27,13 @@ local symtab = upb.SymbolTable{
local factory = upb.MessageFactory(symtab);
local TestMessage = factory:get_message_class("TestMessage")
-function test_decodermethod()
- local decoder = pb.MakeStringToMessageDecoder(TestMessage)
-
- assert_error(
- function()
- -- Needs at least one argument to construct.
- pb.MakeStringToMessageDecoder()
- end)
-end
-
function test_parse_primitive()
local binary_pb =
"\008\128\128\128\128\002\016\128\128\128\128\004\024\128\128"
.. "\128\128\128\128\128\002\032\128\128\128\128\128\128\128\001\041\000"
.. "\000\000\000\000\000\248\063\053\000\000\096\064\056\001"
- local decoder = pb.MakeStringToMessageDecoder(TestMessage)
- local encoder = pb.MakeMessageToStringEncoder(TestMessage)
- collectgarbage() -- ensure encoder/decoder GC-anchor what they need.
- local msg = decoder(binary_pb)
+ local msg = TestMessage()
+ pb.decode(msg, binary_pb)
assert_equal(536870912, msg.i32)
assert_equal(1073741824, msg.u32)
assert_equal(1125899906842624, msg.i64)
@@ -54,8 +42,9 @@ function test_parse_primitive()
assert_equal(3.5, msg.flt)
assert_equal(true, msg.bool)
- local encoded = encoder(msg)
- local msg2 = decoder(encoded)
+ local encoded = pb.encode(msg)
+ local msg2 = TestMessage()
+ pb.decode(msg2, encoded)
assert_equal(536870912, msg.i32)
assert_equal(1073741824, msg.u32)
assert_equal(1125899906842624, msg.i64)
@@ -77,8 +66,8 @@ function test_parse_string()
local TestMessage = factory:get_message_class("TestMessage")
local binary_pb = "\010\005Hello"
- local decoder = pb.MakeStringToMessageDecoder(TestMessage)
- msg = decoder(binary_pb)
+ msg = TestMessage()
+ pb.decode(msg, binary_pb)
assert_equal("Hello", msg.str)
end
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback