Prior to this CL, users were relying on `field->descriptortype` to get the field type. This almost works, as `field->descriptortype` is almost, but not quite, the field type of the field. In two special cases we deviate from the true field type, for ease of parsing and serialization:
- For open enums, we use `kUpb_FieldType_Int32` instead of `kUpb_FieldType_Enum`, because from the perspective of the wire format, an open enum field is equivalent to int32.
- For proto2 strings, we use `kUpb_FieldType_Bytes` instead of `kUpb_FieldType_String`, because proto2 strings do not perform UTF-8 validation, which makes them equivalent to bytes.
In this CL we add a public API function:
```
// Returns the true field type for this field.
upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* f);
```
This will provide the actual field type for this field.
Note that this CL changes the MiniDescriptor format. Previously MiniDescriptors did not contain enough information to distinguish between Enum/Int32. To remedy this we added a new encoded field type, `kUpb_EncodedType_ClosedEnum`.
PiperOrigin-RevId: 479387672
On a 32-bit build, sizeof(upb_Array) was not aligned to 8, and so we were allocating a block of memory that was too small.
Our 32-bit GitHub tests did not catch this, probably because the 32-bit build is not running ASAN. The bug manifested in the 32-bit PHP build.
PiperOrigin-RevId: 478488507
This commit makes a couple changes to allow staleness_test() to be used
from outside the upb repo:
- Fully qualify references to upb targets and wrap them in a Label()
constructor. See here for details:
https://bazel.build/extending/macros#label-resolution
- Make the :staleness_test_lib target public.
This renaming is something we have been planning on doing, and I would
like to do it now because I'm getting ready to rely on this
staleness_test() macro from the main protobuf repo.
Continuing the trend of giving individual build targets their own subdirs
where appropriate, and leaving behind temporary stub headers for compatibility.
JSON is a particularly good choice for this because of how little interaction
it has with the rest of upb.
PiperOrigin-RevId: 476792865
Several data arrays that are used in only one function have been moved from file scope to the function that uses them.
Updated to use C99 array designators so we can specify values by array index. This is more readable and less error-prone than using comments to label each value.
There is no functional change for the vast majority of this CL. The only exception is that we now test for OOM when creating a map.
PiperOrigin-RevId: 475191072
Created a common function for saving/restoring the depth and checking end_group. This will be even more helpful if we decide to add any more state that is saved/resolved when we recurse into a sub-message.
This appears to be perf-neutral.
PiperOrigin-RevId: 475140169
If the extension MiniDescriptor did not contain any fields, we would read an uninitialized value. We need to add a check that the extension descriptor contains exactly one field.
PiperOrigin-RevId: 475075831
- Each def type has its own .c file and its own .h file
- Functions that require a builder context are declared in def_builder.h
- The mini descriptor encoders have also been pulled into upb/reflection/
- upb/def.h, upb/def.hpp, upb/reflection.h, and upb/reflection.hpp are now deprecated stubs that point to the new headers
PiperOrigin-RevId: 474459500