From 6bcdaa13528bd9b924705ae9835dd8f0ca0337d5 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 13 Dec 2018 07:12:58 -0800 Subject: Changed generated array accessors to be more convenient. --- upbc/message_layout.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'upbc/message_layout.cc') diff --git a/upbc/message_layout.cc b/upbc/message_layout.cc index b6614f0..5956424 100644 --- a/upbc/message_layout.cc +++ b/upbc/message_layout.cc @@ -30,16 +30,20 @@ bool MessageLayout::HasHasbit(const protobuf::FieldDescriptor* field) { MessageLayout::SizeAndAlign MessageLayout::SizeOf( const protobuf::FieldDescriptor* field) { - if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED || - field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { - return {{4, 8}, {4, 8}}; + if (field->is_repeated()) { + return {{4, 8}, {4, 8}}; // Pointer to array object. + } else { + return SizeOfUnwrapped(field); } +} +MessageLayout::SizeAndAlign MessageLayout::SizeOfUnwrapped( + const protobuf::FieldDescriptor* field) { switch (field->cpp_type()) { + case protobuf::FieldDescriptor::CPPTYPE_MESSAGE: + return {{4, 8}, {4, 8}}; // Pointer to message. case protobuf::FieldDescriptor::CPPTYPE_STRING: - // upb_stringview - // return {{8, 16}, {4, 8}}; - return {{8, 16}, {8, 16}}; + return {{8, 16}, {4, 8}}; // upb_stringview case protobuf::FieldDescriptor::CPPTYPE_BOOL: return {{1, 1}, {1, 1}}; case protobuf::FieldDescriptor::CPPTYPE_FLOAT: -- cgit v1.2.3