@@ -863,15 +863,15 @@ function toDescriptorType(type, resolvedType, delimited) {
863
863
throw Error ( "illegal type: " + type ) ;
864
864
}
865
865
866
- function fixDescriptorOptionsRecursive ( obj , type ) {
866
+ function fromDescriptorOptionsRecursive ( obj , type ) {
867
867
var val = { } ;
868
868
for ( var i = 0 , field , key ; i < type . fieldsArray . length ; ++ i ) {
869
869
if ( ( key = ( field = type . _fieldsArray [ i ] ) . name ) === "uninterpretedOption" ) continue ;
870
870
if ( ! Object . prototype . hasOwnProperty . call ( obj , key ) ) continue ;
871
871
872
872
var newKey = underScore ( key ) ;
873
873
if ( field . resolvedType instanceof Type ) {
874
- val [ newKey ] = fixDescriptorOptionsRecursive ( obj [ key ] , field . resolvedType ) ;
874
+ val [ newKey ] = fromDescriptorOptionsRecursive ( obj [ key ] , field . resolvedType ) ;
875
875
} else if ( field . resolvedType instanceof Enum ) {
876
876
val [ newKey ] = field . resolvedType . valuesById [ obj [ key ] ] ;
877
877
} else {
@@ -885,19 +885,24 @@ function fixDescriptorOptionsRecursive(obj, type) {
885
885
function fromDescriptorOptions ( options , type ) {
886
886
if ( ! options )
887
887
return undefined ;
888
- return fixDescriptorOptionsRecursive ( type . toObject ( options ) , type ) ;
888
+ return fromDescriptorOptionsRecursive ( type . toObject ( options ) , type ) ;
889
889
}
890
890
891
- function camelCaseRecursive ( obj ) {
891
+ function toDescriptorOptionsRecursive ( obj , type ) {
892
892
var val = { } ;
893
893
var keys = Object . keys ( obj ) ;
894
894
for ( var i = 0 ; i < keys . length ; ++ i ) {
895
895
var key = keys [ i ] ;
896
896
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 ) ;
899
901
} 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 ] ] ;
901
906
}
902
907
}
903
908
return val ;
@@ -907,7 +912,7 @@ function camelCaseRecursive(obj) {
907
912
function toDescriptorOptions ( options , type ) {
908
913
if ( ! options )
909
914
return undefined ;
910
- return type . fromObject ( camelCaseRecursive ( options ) ) ;
915
+ return type . fromObject ( toDescriptorOptionsRecursive ( options , type ) ) ;
911
916
}
912
917
913
918
// Calculates the shortest relative path from `from` to `to`.
0 commit comments