1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2024 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #include "upb/wire/byte_size.h" 9 10 #include <stddef.h> 11 12 #include "upb/mem/arena.h" 13 #include "upb/message/message.h" 14 #include "upb/mini_table/message.h" 15 #include "upb/wire/encode.h" 16 17 // Must be last. 18 #include "upb/port/def.inc" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 upb_ByteSize(const upb_Message * msg,const upb_MiniTable * mt)24size_t upb_ByteSize(const upb_Message* msg, const upb_MiniTable* mt) { 25 upb_Arena* arena = upb_Arena_New(); 26 char* buf; 27 size_t res = 0; 28 29 upb_Encode(msg, mt, 0, arena, &buf, &res); 30 31 upb_Arena_Free(arena); 32 return res; 33 } 34 35 #ifdef __cplusplus 36 } // extern "C" 37 #endif