From 8875220f1f487abbe821c5536e9e00c52685729d Mon Sep 17 00:00:00 2001 From: Whislly Date: Thu, 25 Feb 2021 20:26:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=BF=E7=94=A8protobuf3=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81repeated=E4=BF=AE=E9=A5=B0=E7=9A=84?= =?UTF-8?q?=E7=AE=80=E5=8D=95=E7=B1=BB=E5=9E=8B=EF=BC=88=E4=BE=8B=E5=A6=82?= =?UTF-8?q?:repeated=20int32=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在我们项目中,发现协议里面加了类似repeated int32的类型,客户端不论发多少个数字,pbc只能解析出来一个错误的数字 --- src/decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decode.c b/src/decode.c index f8b2f50..b22b57a 100644 --- a/src/decode.c +++ b/src/decode.c @@ -328,7 +328,7 @@ pbc_decode(struct pbc_env * env, const char * type_name , struct pbc_slice * sli _pbcC_close(_ctx); return -i-1; } - } else if (f->label == LABEL_PACKED) { + } else if (f->label == LABEL_PACKED || f->label == LABEL_REPEATED) { struct atom * a = &ctx->a[i]; int n = call_array(pd, ud, f , start + a->v.s.start , a->v.s.end - a->v.s.start); if (n < 0) { From 8ba46eaad026b912f41acf1cca91cbb924004038 Mon Sep 17 00:00:00 2001 From: Whislly Date: Sat, 20 Mar 2021 11:15:28 +0800 Subject: [PATCH 2/2] support protobuf3 : repeated default use packed --- src/decode.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/decode.c b/src/decode.c index b22b57a..cf0cfca 100644 --- a/src/decode.c +++ b/src/decode.c @@ -328,12 +328,29 @@ pbc_decode(struct pbc_env * env, const char * type_name , struct pbc_slice * sli _pbcC_close(_ctx); return -i-1; } - } else if (f->label == LABEL_PACKED || f->label == LABEL_REPEATED) { - struct atom * a = &ctx->a[i]; - int n = call_array(pd, ud, f , start + a->v.s.start , a->v.s.end - a->v.s.start); + } else if (f->label == LABEL_PACKED) { + struct atom* a = &ctx->a[i]; + int n = call_array(pd, ud, f, start + a->v.s.start, a->v.s.end - a->v.s.start); if (n < 0) { _pbcC_close(_ctx); - return -i-1; + return -i - 1; + } + } + else if (f->label == LABEL_REPEATED) { + if ((f->type == PTYPE_STRING) || + (f->type == PTYPE_BYTES) || + (f->type == PTYPE_MESSAGE)) { + if (call_type(pd, ud, f, &ctx->a[i], start) != 0) { + _pbcC_close(_ctx); + return -i - 1; + } + } else { + struct atom* a = &ctx->a[i]; + int n = call_array(pd, ud, f, start + a->v.s.start, a->v.s.end - a->v.s.start); + if (n < 0) { + _pbcC_close(_ctx); + return -i - 1; + } } } else { if (call_type(pd,ud,f,&ctx->a[i],start) != 0) {