|
|
|
@ -57,6 +57,28 @@ size_t native_slot_size(upb_fieldtype_t type) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VALUE value_from_default(const upb_fielddef *field) { |
|
|
|
|
switch (upb_fielddef_type(field)) { |
|
|
|
|
case UPB_TYPE_FLOAT: return DBL2NUM(upb_fielddef_defaultfloat(field)); |
|
|
|
|
case UPB_TYPE_DOUBLE: return DBL2NUM(upb_fielddef_defaultdouble(field)); |
|
|
|
|
case UPB_TYPE_BOOL: |
|
|
|
|
return upb_fielddef_defaultbool(field) ? Qtrue : Qfalse; |
|
|
|
|
case UPB_TYPE_MESSAGE: return Qnil; |
|
|
|
|
case UPB_TYPE_ENUM: return INT2NUM(upb_fielddef_defaultint32(field)); |
|
|
|
|
case UPB_TYPE_INT32: return INT2NUM(upb_fielddef_defaultint32(field)); |
|
|
|
|
case UPB_TYPE_INT64: return LL2NUM(upb_fielddef_defaultint64(field));; |
|
|
|
|
case UPB_TYPE_UINT32: return UINT2NUM(upb_fielddef_defaultuint32(field)); |
|
|
|
|
case UPB_TYPE_UINT64: return ULL2NUM(upb_fielddef_defaultuint64(field)); |
|
|
|
|
case UPB_TYPE_STRING: |
|
|
|
|
case UPB_TYPE_BYTES: { |
|
|
|
|
size_t size; |
|
|
|
|
const char *str = upb_fielddef_defaultstr(field, &size); |
|
|
|
|
return rb_str_new(str, size); |
|
|
|
|
} |
|
|
|
|
default: return Qnil; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool is_ruby_num(VALUE value) { |
|
|
|
|
return (TYPE(value) == T_FLOAT || |
|
|
|
|
TYPE(value) == T_FIXNUM || |
|
|
|
@ -537,7 +559,7 @@ VALUE layout_get(MessageLayout* layout, |
|
|
|
|
|
|
|
|
|
if (upb_fielddef_containingoneof(field)) { |
|
|
|
|
if (*oneof_case != upb_fielddef_number(field)) { |
|
|
|
|
return Qnil; |
|
|
|
|
return value_from_default(field); |
|
|
|
|
} |
|
|
|
|
return native_slot_get(upb_fielddef_type(field), |
|
|
|
|
field_type_class(field), |
|
|
|
|