@@ -863,15 +863,15 @@ function toDescriptorType(type, resolvedType, delimited) {
863863 throw Error ( "illegal type: " + type ) ;
864864}
865865
866- function fixDescriptorOptionsRecursive ( obj , type ) {
866+ function fromDescriptorOptionsRecursive ( obj , type ) {
867867 var val = { } ;
868868 for ( var i = 0 , field , key ; i < type . fieldsArray . length ; ++ i ) {
869869 if ( ( key = ( field = type . _fieldsArray [ i ] ) . name ) === "uninterpretedOption" ) continue ;
870870 if ( ! Object . prototype . hasOwnProperty . call ( obj , key ) ) continue ;
871871
872872 var newKey = underScore ( key ) ;
873873 if ( field . resolvedType instanceof Type ) {
874- val [ newKey ] = fixDescriptorOptionsRecursive ( obj [ key ] , field . resolvedType ) ;
874+ val [ newKey ] = fromDescriptorOptionsRecursive ( obj [ key ] , field . resolvedType ) ;
875875 } else if ( field . resolvedType instanceof Enum ) {
876876 val [ newKey ] = field . resolvedType . valuesById [ obj [ key ] ] ;
877877 } else {
@@ -885,19 +885,24 @@ function fixDescriptorOptionsRecursive(obj, type) {
885885function fromDescriptorOptions ( options , type ) {
886886 if ( ! options )
887887 return undefined ;
888- return fixDescriptorOptionsRecursive ( type . toObject ( options ) , type ) ;
888+ return fromDescriptorOptionsRecursive ( type . toObject ( options ) , type ) ;
889889}
890890
891- function camelCaseRecursive ( obj ) {
891+ function toDescriptorOptionsRecursive ( obj , type ) {
892892 var val = { } ;
893893 var keys = Object . keys ( obj ) ;
894894 for ( var i = 0 ; i < keys . length ; ++ i ) {
895895 var key = keys [ i ] ;
896896 var newKey = $protobuf . util . camelCase ( key ) ;
897- if ( typeof obj [ key ] !== "object" ) {
898- val [ newKey ] = obj [ key ] ;
897+ if ( ! Object . prototype . hasOwnProperty . call ( type . fields , newKey ) ) continue ;
898+ var field = type . fields [ newKey ] ;
899+ if ( field . resolvedType instanceof Type ) {
900+ val [ newKey ] = toDescriptorOptionsRecursive ( obj [ key ] , field . resolvedType ) ;
899901 } else {
900- val [ newKey ] = camelCaseRecursive ( obj [ key ] ) ;
902+ val [ newKey ] = obj [ key ] ;
903+ }
904+ if ( field . repeated && ! Array . isArray ( val [ newKey ] ) ) {
905+ val [ newKey ] = [ val [ newKey ] ] ;
901906 }
902907 }
903908 return val ;
@@ -907,7 +912,7 @@ function camelCaseRecursive(obj) {
907912function toDescriptorOptions ( options , type ) {
908913 if ( ! options )
909914 return undefined ;
910- return type . fromObject ( camelCaseRecursive ( options ) ) ;
915+ return type . fromObject ( toDescriptorOptionsRecursive ( options , type ) ) ;
911916}
912917
913918// Calculates the shortest relative path from `from` to `to`.
0 commit comments