Merge pull request #315 from haberman/conformance-fixes

Updated to a new version of protobuf and fixed a few conformance tests.
pull/13171/head
Joshua Haberman 4 years ago committed by GitHub
commit 2a0425ecf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      bazel/workspace_deps.bzl
  2. 54
      upb/json_decode.c
  3. 13
      upb/json_encode.c

@ -16,7 +16,7 @@ def upb_deps():
git_repository,
name = "com_google_protobuf",
remote = "https://github.com/protocolbuffers/protobuf.git",
commit = "5f5efe50c5bef20042645b51a697f58b0704ac89", # Need to use Git until proto3 optional is released
commit = "c8f76331abf682c289fa79f05b2ee39cc7bf5a48", # Need to use Git until proto3 optional is released
)
maybe(

@ -42,6 +42,19 @@ static bool jsondec_streql(upb_strview str, const char *lit) {
return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0;
}
static bool jsondec_isnullvalue(const upb_fielddef *f) {
return upb_fielddef_type(f) == UPB_TYPE_ENUM &&
strcmp(upb_enumdef_fullname(upb_fielddef_enumsubdef(f)),
"google.protobuf.NullValue") == 0;
}
static bool jsondec_isvalue(const upb_fielddef *f) {
return (upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(f)) ==
UPB_WELLKNOWN_VALUE) ||
jsondec_isnullvalue(f);
}
UPB_NORETURN static void jsondec_err(jsondec *d, const char *msg) {
upb_status_seterrf(d->status, "Error parsing JSON @%d:%d: %s", d->line,
(int)(d->ptr - d->line_begin), msg);
@ -769,21 +782,32 @@ static upb_msgval jsondec_strfield(jsondec *d, const upb_fielddef *f) {
}
static upb_msgval jsondec_enum(jsondec *d, const upb_fielddef *f) {
if (jsondec_peek(d) == JD_STRING) {
const upb_enumdef *e = upb_fielddef_enumsubdef(f);
upb_strview str = jsondec_string(d);
upb_msgval val;
if (!upb_enumdef_ntoi(e, str.data, str.size, &val.int32_val)) {
if (d->options & UPB_JSONDEC_IGNOREUNKNOWN) {
switch (jsondec_peek(d)) {
case JD_STRING: {
const upb_enumdef *e = upb_fielddef_enumsubdef(f);
upb_strview str = jsondec_string(d);
upb_msgval val;
if (!upb_enumdef_ntoi(e, str.data, str.size, &val.int32_val)) {
if (d->options & UPB_JSONDEC_IGNOREUNKNOWN) {
val.int32_val = 0;
} else {
jsondec_errf(d, "Unknown enumerator: '" UPB_STRVIEW_FORMAT "'",
UPB_STRVIEW_ARGS(str));
}
}
return val;
}
case JD_NULL: {
if (jsondec_isnullvalue(f)) {
upb_msgval val;
jsondec_null(d);
val.int32_val = 0;
} else {
jsondec_errf(d, "Unknown enumerator: '" UPB_STRVIEW_FORMAT "'",
UPB_STRVIEW_ARGS(str));
return val;
}
}
return val;
} else {
return jsondec_int(d, f);
/* Fallthrough. */
default:
return jsondec_int(d, f);
}
}
@ -867,12 +891,6 @@ static upb_msgval jsondec_msg(jsondec *d, const upb_fielddef *f) {
return val;
}
static bool jsondec_isvalue(const upb_fielddef *f) {
return upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
upb_msgdef_wellknowntype(upb_fielddef_msgsubdef(f)) ==
UPB_WELLKNOWN_VALUE;
}
static void jsondec_field(jsondec *d, upb_msg *msg, const upb_msgdef *m) {
upb_strview name;
const upb_fielddef *f;

@ -167,12 +167,17 @@ static void jsonenc_duration(jsonenc *e, const upb_msg *msg, const upb_msgdef *m
static void jsonenc_enum(int32_t val, const upb_fielddef *f, jsonenc *e) {
const upb_enumdef *e_def = upb_fielddef_enumsubdef(f);
const char *name = upb_enumdef_iton(e_def, val);
if (name) {
jsonenc_printf(e, "\"%s\"", name);
if (strcmp(upb_enumdef_fullname(e_def), "google.protobuf.NullValue") == 0) {
jsonenc_putstr(e, "null");
} else {
jsonenc_printf(e, "%" PRId32, val);
const char *name = upb_enumdef_iton(e_def, val);
if (name) {
jsonenc_printf(e, "\"%s\"", name);
} else {
jsonenc_printf(e, "%" PRId32, val);
}
}
}

Loading…
Cancel
Save