@@ -751,11 +751,13 @@ MultiDimArray.prototype.compose = function(STable, repr_info_hash) {
751
751
var type = repr_info_hash . content . get ( 'array' ) . content . get ( 'type' ) ;
752
752
753
753
if ( type ) {
754
- STable . type = type . _STable . REPR . boxed_primitive ;
754
+ STable . primType = type . _STable . REPR . boxed_primitive ;
755
755
} else {
756
- STable . type = 0 ;
756
+ STable . primType = 0 ;
757
757
}
758
758
759
+ STable . type = type || null ;
760
+
759
761
if ( dimensions instanceof NQPInt ) {
760
762
dimensions = dimensions . value ;
761
763
if ( dimensions === 0 ) {
@@ -846,42 +848,42 @@ MultiDimArray.prototype.create_obj_constructor = function(STable) {
846
848
} ) ;
847
849
848
850
STable . addInternalMethod ( '$$atposnd' , function ( idx ) {
849
- if ( STable . type != 0 ) throw new NQPException ( "wrong type" ) ;
851
+ if ( STable . primType != 0 ) throw new NQPException ( "wrong type" ) ;
850
852
return this . storage [ this . $$calculateIndex ( idx ) ] ;
851
853
} ) ;
852
854
853
855
STable . addInternalMethod ( '$$bindposnd' , function ( idx , value ) {
854
- if ( STable . type != 0 ) throw new NQPException ( "wrong type: " + STable . type ) ;
856
+ if ( STable . primType != 0 ) throw new NQPException ( "wrong type: " + STable . primType ) ;
855
857
return ( this . storage [ this . $$calculateIndex ( idx ) ] = value ) ;
856
858
} ) ;
857
859
858
860
STable . addInternalMethod ( '$$atposnd_i' , function ( idx ) {
859
- if ( STable . type != 1 ) throw new NQPException ( "wrong type: " + STable . type ) ;
861
+ if ( STable . primType != 1 ) throw new NQPException ( "wrong type: " + STable . primType ) ;
860
862
return this . storage [ this . $$calculateIndex ( idx ) ] ;
861
863
} ) ;
862
864
863
865
STable . addInternalMethod ( '$$bindposnd_i' , function ( idx , value ) {
864
- if ( STable . type != 1 ) throw new NQPException ( "wrong type" + STable . type ) ;
866
+ if ( STable . primType != 1 ) throw new NQPException ( "wrong type" + STable . primType ) ;
865
867
return ( this . storage [ this . $$calculateIndex ( idx ) ] = value ) ;
866
868
} ) ;
867
869
868
870
STable . addInternalMethod ( '$$atposnd_n' , function ( idx ) {
869
- if ( STable . type != 2 ) throw new NQPException ( "wrong type" ) ;
871
+ if ( STable . primType != 2 ) throw new NQPException ( "wrong type" ) ;
870
872
return this . storage [ this . $$calculateIndex ( idx ) ] ;
871
873
} ) ;
872
874
873
875
STable . addInternalMethod ( '$$bindposnd_n' , function ( idx , value ) {
874
- if ( STable . type != 2 ) throw new NQPException ( "wrong type" ) ;
876
+ if ( STable . primType != 2 ) throw new NQPException ( "wrong type" ) ;
875
877
return ( this . storage [ this . $$calculateIndex ( idx ) ] = value ) ;
876
878
} ) ;
877
879
878
880
STable . addInternalMethod ( '$$atposnd_s' , function ( idx ) {
879
- if ( STable . type != 3 ) throw new NQPException ( "wrong type" ) ;
881
+ if ( STable . primType != 3 ) throw new NQPException ( "wrong type" ) ;
880
882
return this . storage [ this . $$calculateIndex ( idx ) ] ;
881
883
} ) ;
882
884
883
885
STable . addInternalMethod ( '$$bindposnd_s' , function ( idx , value ) {
884
- if ( STable . type != 3 ) throw new NQPException ( "wrong type" ) ;
886
+ if ( STable . primType != 3 ) throw new NQPException ( "wrong type" ) ;
885
887
return ( this . storage [ this . $$calculateIndex ( idx ) ] = value ) ;
886
888
} ) ;
887
889
@@ -906,4 +908,79 @@ MultiDimArray.prototype.create_obj_constructor = function(STable) {
906
908
return c ;
907
909
} ;
908
910
911
+ MultiDimArray . prototype . serialize_repr_data = function ( st , cursor ) {
912
+ if ( st . dimensions ) {
913
+ cursor . varint ( st . dimensions ) ;
914
+ cursor . ref ( st . type ) ;
915
+ } else {
916
+ cursor . varint ( 0 ) ;
917
+ }
918
+
919
+ } ;
920
+
921
+ MultiDimArray . prototype . deserialize_repr_data = function ( cursor , STable ) {
922
+ var dims = cursor . varint ( ) ;
923
+ if ( dims > 0 ) {
924
+ STable . dimensions = dims ;
925
+ STable . type = cursor . variant ( ) ;
926
+ STable . primType = STable . type ? STable . type . _STable . REPR . boxed_primitive : 0 ;
927
+ }
928
+ } ;
929
+
930
+ MultiDimArray . prototype . valuesSize = function ( object ) {
931
+ var size = 1 ;
932
+ for ( var i = 0 ; i < object . dimensions . length ; i ++ ) {
933
+ size = size * object . dimensions [ i ] ;
934
+ }
935
+ return size ;
936
+ } ;
937
+
938
+ MultiDimArray . prototype . serialize = function ( cursor , obj ) {
939
+ for ( var i = 0 ; i < obj . _STable . dimensions ; i ++ ) {
940
+ cursor . varint ( obj . dimensions [ i ] ) ;
941
+ }
942
+ var size = this . valuesSize ( obj ) ;
943
+ for ( var i = 0 ; i < size ; i ++ ) {
944
+ switch ( obj . _STable . primType ) {
945
+ case 0 :
946
+ cursor . ref ( obj . storage [ i ] ) ;
947
+ break ;
948
+ case 1 :
949
+ cursor . varint ( obj . storage [ i ] ) ;
950
+ break ;
951
+ case 2 :
952
+ cursor . double ( obj . storage [ i ] ) ;
953
+ break ;
954
+ case 3 :
955
+ cursor . str ( obj . storage [ i ] ) ;
956
+ break ;
957
+ }
958
+ }
959
+ }
960
+
961
+ MultiDimArray . prototype . deserialize_finish = function ( object , data ) {
962
+ object . dimensions = [ ] ;
963
+ for ( var i = 0 ; i < object . _STable . dimensions ; i ++ ) {
964
+ object . dimensions [ i ] = data . varint ( ) ;
965
+ }
966
+ var size = this . valuesSize ( object ) ;
967
+ object . storage = [ ] ;
968
+ for ( var i = 0 ; i < size ; i ++ ) {
969
+ switch ( object . _STable . primType ) {
970
+ case 0 :
971
+ object . storage [ i ] = data . variant ( ) ;
972
+ break ;
973
+ case 1 :
974
+ object . storage [ i ] = data . varint ( ) ;
975
+ break ;
976
+ case 2 :
977
+ object . storage [ i ] = data . double ( ) ;
978
+ break ;
979
+ case 3 :
980
+ object . storage [ i ] = data . str ( ) ;
981
+ break ;
982
+ }
983
+ }
984
+ } ;
985
+
909
986
module . exports . MultiDimArray = MultiDimArray ;
0 commit comments