passing 'pb_callback_t' to parameter of incompatible type ' '

17 views
Skip to first unread message

Leonard x

unread,
Jan 11, 2024, 1:03:12 AMJan 11
to nanopb
Please help
I'm learning to use nanopb in stm32
I find some examples from website and complie them in keil
there are some error about pb_callback_t

for example
static bool courseScoreEncode(pb_ostream_t* stream, const pb_field_t* field, void* const* arg){
    StudentInfo *studentInfo=(StudentInfo *)*arg;
    CourseScore stuCourseScore;
    for(int i=0;i<studentInfo->realCourseNum;i++){

//error:passing 'pb_callback_t'(aka 'struct pb_callback_s') to parameter of incompatible type 'char * '
        strcpy(stuCourseScore.coursename,studentInfo->coursescores[i].coursename);
        stuCourseScore.score=studentInfo->coursescores[i].score;
        if (!pb_encode_tag_for_field(stream, field)) {
            return false;
        }
        if (!pb_encode_submessage(stream, CourseScore_fields, &stuCourseScore)) {
            return false;
        }
    }
    return true;
}


proto:
syntax = "proto3";
//import "nanopb.proto";
message CourseScore{
     string coursename = 1;
     uint32 score      = 2;
}
message Student
{
      string name              = 1;
      uint32 studentid         = 2;
      string phonenum          = 3;
     repeated CourseScore coursescores = 4;
}

thank you for your help

Petteri Aimonen

unread,
Jan 11, 2024, 1:05:54 AMJan 11
to nan...@googlegroups.com
Hi,
You need to specify maximum size for the Student.name field.
For example by:

string name = 1 [(nanopb).max_size = 32];

or in a separate .options file:
https://jpa.kapsi.fi/nanopb/docs/reference.html#defining-the-options-in-a-.options-file

--
Petteri
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/nanopb/6d086c59-19fc-4703-86d2-e40800093a8an%40googlegroups.com.
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [1]nanopb+un...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/nanopb/6d086c59-19fc-4703-86d2-e40
> 800093a8an%40googlegroups.com.
>
> References
>
> 1. mailto:nanopb+un...@googlegroups.com
> 2. https://groups.google.com/d/msgid/nanopb/6d086c59-19fc-4703...@googlegroups.com?utm_medium=email&utm_source=footer


Reply all
Reply to author
Forward
0 new messages