move message set enums into upb/wire/ (and use them)

PiperOrigin-RevId: 486366363
pull/13171/head
Eric Salo 2 years ago committed by Copybara-Service
parent 5f1ff7c94a
commit 46699b72ad
  1. 1
      BUILD
  2. 14
      upb/msg_internal.h
  3. 50
      upb/wire/common_internal.h
  4. 11
      upb/wire/decode.c
  5. 15
      upb/wire/encode.c

@ -1031,6 +1031,7 @@ cc_library(
"upb/wire/decode.h",
],
hdrs = [
"upb/wire/common_internal.h",
"upb/wire/decode_internal.h",
"upb/wire/encode_internal.h",
],

@ -201,20 +201,6 @@ typedef enum {
kUpb_ExtMode_IsMapEntry = 4,
} upb_ExtMode;
/* MessageSet wire format is:
* message MessageSet {
* repeated group Item = 1 {
* required int32 type_id = 2;
* required bytes message = 3;
* }
* }
*/
typedef enum {
_UPB_MSGSET_ITEM = 1,
_UPB_MSGSET_TYPEID = 2,
_UPB_MSGSET_MESSAGE = 3,
} upb_msgext_fieldnum;
struct upb_MiniTable {
const upb_MiniTable_Sub* subs;
const upb_MiniTable_Field* fields;

@ -0,0 +1,50 @@
/*
* Copyright (c) 2009-2021, Google LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Google LLC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_WIRE_COMMON_INTERNAL_H_
#define UPB_WIRE_COMMON_INTERNAL_H_
// Must be last.
#include "upb/port_def.inc"
// MessageSet wire format is:
// message MessageSet {
// repeated group Item = 1 {
// required int32 type_id = 2;
// required bytes message = 3;
// }
// }
enum {
kUpb_MsgSet_Item = 1,
kUpb_MsgSet_TypeId = 2,
kUpb_MsgSet_Message = 3,
};
#include "upb/port_undef.inc"
#endif /* UPB_WIRE_COMMON_INTERNAL_H_ */

@ -32,6 +32,7 @@
#include "upb/collections/array_internal.h"
#include "upb/collections/map_internal.h"
#include "upb/upb.h"
#include "upb/wire/common_internal.h"
#include "upb/wire/decode_internal.h"
// Must be last.
@ -748,10 +749,10 @@ static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr,
}
enum {
kStartItemTag = ((1 << 3) | kUpb_WireType_StartGroup),
kEndItemTag = ((1 << 3) | kUpb_WireType_EndGroup),
kTypeIdTag = ((2 << 3) | kUpb_WireType_Varint),
kMessageTag = ((3 << 3) | kUpb_WireType_Delimited),
kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup),
kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup),
kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint),
kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited),
};
static void upb_Decoder_AddKnownMessageSetItem(
@ -899,7 +900,7 @@ static const upb_MiniTable_Field* _upb_Decoder_FindField(
break;
}
case kUpb_ExtMode_IsMessageSet:
if (field_number == _UPB_MSGSET_ITEM) {
if (field_number == kUpb_MsgSet_Item) {
static upb_MiniTable_Field item = {
0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0};
return &item;

@ -33,6 +33,7 @@
#include "upb/collections/array_internal.h"
#include "upb/collections/map_sorter_internal.h"
#include "upb/wire/common_internal.h"
// Must be last.
#include "upb/port_def.inc"
@ -495,22 +496,16 @@ static void encode_field(upb_encstate* e, const upb_Message* msg,
}
}
/* message MessageSet {
* repeated group Item = 1 {
* required int32 type_id = 2;
* required string message = 3;
* }
* } */
static void encode_msgset_item(upb_encstate* e,
const upb_Message_Extension* ext) {
size_t size;
encode_tag(e, 1, kUpb_WireType_EndGroup);
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup);
encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size);
encode_varint(e, size);
encode_tag(e, 3, kUpb_WireType_Delimited);
encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited);
encode_varint(e, ext->ext->field.number);
encode_tag(e, 2, kUpb_WireType_Varint);
encode_tag(e, 1, kUpb_WireType_StartGroup);
encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint);
encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup);
}
static void encode_message(upb_encstate* e, const upb_Message* msg,

Loading…
Cancel
Save