@@ -643,6 +643,9 @@ static int Get_var_type(Bmi *self, const char *name, char *type) {
643643 if (strcmp (name , "serialization_create" ) == 0 ) {
644644 strncpy (type , "uint64_t" , BMI_MAX_TYPE_NAME );
645645 return BMI_SUCCESS ;
646+ } else if (strcmp (name , "serialization_size" ) == 0 ) {
647+ strncpy (type , "uint64_t" , BMI_MAX_TYPE_NAME );
648+ return BMI_SUCCESS ;
646649 } else if (strcmp (name , "serialization_state" ) == 0 ) {
647650 strncpy (type , "char" , BMI_MAX_TYPE_NAME );
648651 return BMI_SUCCESS ;
@@ -773,7 +776,7 @@ static int Get_var_nbytes(Bmi *self, const char *name, int *nbytes) {
773776 }
774777 // special cases for save state
775778 if (item_count < 1 ) {
776- if (strcmp (name , "serialization_create" ) == 0 || strcmp (name , "serialization_free" ) == 0 ) {
779+ if (strcmp (name , "serialization_create" ) == 0 || strcmp (name , "serialization_size" ) == 0 || strcmp ( name , " serialization_free" ) == 0 ) {
777780 item_count = 1 ;
778781 } else if (strcmp (name , "serialization_state" ) == 0 ) {
779782 topmodel_model * model = (topmodel_model * )self -> data ;
@@ -975,18 +978,18 @@ static int Get_value_ptr(Bmi *self, const char *name, void **dest) {
975978 }
976979
977980 // serialization commands
978- if (strcmp (name , "serialization_create" ) == 0 ) {
979- // create new serialized data
980- if (serialize_topmodel (self ) != BMI_SUCCESS )
981- return BMI_FAILURE ;
981+ if (strcmp (name , "serialization_state" ) == 0 ) {
982982 topmodel_model * topmodel = (topmodel_model * )self -> data ;
983- * dest = & topmodel -> serialized_length ;
983+ if (topmodel -> serialized == NULL )
984+ return BMI_FAILURE ;
985+ * dest = topmodel -> serialized ;
984986 return BMI_SUCCESS ;
985- } else if (strcmp (name , "serialization_state" ) == 0 ) {
987+ }
988+ if (strcmp (name , "serialization_size" ) == 0 ) {
986989 topmodel_model * topmodel = (topmodel_model * )self -> data ;
987990 if (topmodel -> serialized == NULL )
988991 return BMI_FAILURE ;
989- * dest = topmodel -> serialized ;
992+ * dest = ( void * ) & topmodel -> serialized_length ;
990993 return BMI_SUCCESS ;
991994 }
992995
@@ -1043,6 +1046,11 @@ static int Set_value(Bmi *self, const char *name, void *array) {
10431046 model -> serialized = NULL ;
10441047 model -> serialized_length = 0 ;
10451048 return BMI_SUCCESS ;
1049+ } else if (strcmp (name , "serialization_create" ) == 0 ) {
1050+ // create new serialized data
1051+ if (serialize_topmodel (self ) != BMI_SUCCESS )
1052+ return BMI_FAILURE ;
1053+ return BMI_SUCCESS ;
10461054 } else if (strcmp (name , "serialization_state" ) == 0 ) {
10471055 if (deserialize_topmodel (self , (char * )array ) == BMI_SUCCESS ) {
10481056 topmodel_model * model = (topmodel_model * )self -> data ;
@@ -1055,9 +1063,6 @@ static int Set_value(Bmi *self, const char *name, void *array) {
10551063 } else {
10561064 return BMI_FAILURE ;
10571065 }
1058- } else if (strcmp (name , "serialization_create" ) == 0 ) {
1059- Log (WARNING , "Cannot set a value with \"serialization_create\"." );
1060- return BMI_FAILURE ;
10611066 }
10621067
10631068 if (self -> get_value_ptr (self , name , & dest ) == BMI_FAILURE )
0 commit comments