pull/13171/head
theodorerose 3 years ago
parent 721b077724
commit 97273a3638
  1. 17
      upb/decode.c
  2. 26
      upb/msg_test.cc
  3. 19
      upb/msg_test.proto

@ -412,15 +412,20 @@ static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr,
return false;
}
#include <stdio.h>
UPB_FORCEINLINE
static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg,
const upb_MiniTable_Enum* e,
const upb_MiniTable_Field* field, wireval* val) {
uint32_t v = val->uint32_val;
printf("@test:we are here\n");
if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true;
return decode_checkenum_slow(d, ptr, msg, e, field, v);
printf("@test:we are here 2\n");
bool ans = decode_checkenum_slow(d, ptr, msg, e, field, v);
printf("@test:%d\n", (int)ans);
return ans;
}
UPB_NOINLINE
@ -628,7 +633,15 @@ static const char* decode_tomap(upb_Decoder* d, const char* ptr,
}
ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size);
_upb_Map_Set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena);
// check if ent had any unknown fields
size_t size;
const char* unknown = upb_Message_GetUnknown(&ent.k, &size);
printf("@test:size = %d %p\n", (int)size, unknown);
if(size != 0) {
} else {
_upb_Map_Set(map, &ent.k, map->key_size, &ent.v, map->val_size, &d->arena);
}
return ptr;
}

@ -398,3 +398,29 @@ TEST(MessageTest, MaxRequiredFields) {
test_msg, kUpb_Encode_CheckRequired, arena.ptr(), &size);
ASSERT_TRUE(serialized != nullptr);
}
TEST(MessageTest, MapField) {
upb::Arena arena;
upb_test_TestMapFieldExtra* test_msg_extra =
upb_test_TestMapFieldExtra_new(arena.ptr());
ASSERT_TRUE(upb_test_TestMapFieldExtra_map_field_set(test_msg_extra, 0, upb_test_TestMapFieldExtra_THREE, arena.ptr()));
size_t size;
char* serialized = upb_test_TestMapFieldExtra_serialize_ex(
test_msg_extra, 0, arena.ptr(), &size);
ASSERT_NE(nullptr, serialized);
ASSERT_NE(0, size);
upb_test_TestMapField* test_msg = upb_test_TestMapField_parse(serialized, size, arena.ptr());
ASSERT_NE(nullptr, test_msg);
ASSERT_FALSE(upb_test_TestMapField_map_field_get(test_msg, 0, nullptr));
serialized = upb_test_TestMapField_serialize_ex(
test_msg, 0, arena.ptr(), &size);
ASSERT_NE(0, size);
// parse into second instance
upb_test_TestMapFieldExtra* test_msg_extra2 =
upb_test_TestMapFieldExtra_parse(serialized, size, arena.ptr());
ASSERT_TRUE(upb_test_TestMapFieldExtra_map_field_get(test_msg_extra2, 0, nullptr));
}

@ -158,3 +158,22 @@ message TestMaxRequiredFields {
required int32 required_int32_61 = 61;
required int32 required_int32_62 = 62;
}
message TestMapField {
enum EnumMap {
ZERO = 0;
ONE = 1;
TWO = 2;
}
map<int32, EnumMap> map_field = 1;
}
message TestMapFieldExtra {
enum EnumMap {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
}
map<int32, EnumMap> map_field = 1;
}

Loading…
Cancel
Save