]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add support for strings that are longer than 127 characters 66/1466/2
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 15 Feb 2018 09:05:53 +0000 (11:05 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 15 Feb 2018 10:42:03 +0000 (12:42 +0200)
refs #7770

Change-Id: I60990b0f3a0c8051abc43b824df1a88afc07bc87

bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java

index ef1ced835a19f74d5d1d774ad0b8575f603e2c5f..e9ecce63c8ba0eac39b71e933edb801247f17b04 100644 (file)
@@ -61,43 +61,45 @@ public class WriteBindings {
 
                        int byteIndex = 0;
                        byte[] bytearr;
-
-                       if(utflen < 0x80) {
+                       
+                       int lengthTester = utflen;
+                       
+                       if(lengthTester < 0x80) {
                                bytearr = new byte[utflen+1];
                                bytearr[byteIndex++] = ((byte)utflen);
                        }
                        else {
-                               utflen -= 0x80;
-                               if(utflen < 0x4000) {
+                               lengthTester -= 0x80;
+                               if(lengthTester < 0x4000) {
                                        bytearr = new byte[utflen+2];
-                                       bytearr[byteIndex++] = (byte)( ((utflen&0x3f) | 0x80) );
-                                       bytearr[byteIndex++] = (byte)( (utflen>>>6) );
+                                       bytearr[byteIndex++] = (byte)( ((lengthTester&0x3f) | 0x80) );
+                                       bytearr[byteIndex++] = (byte)( (lengthTester>>>6) );
                                }
                                else {
-                                       utflen -= 0x4000;
-                                       if(utflen < 0x200000) {
+                                       lengthTester -= 0x4000;
+                                       if(lengthTester < 0x200000) {
                                                bytearr = new byte[utflen+3];
-                                               bytearr[byteIndex++] = (byte)( ((utflen&0x1f) | 0xc0) );
-                                               bytearr[byteIndex++] = (byte)( ((utflen>>>5)&0xff) );
-                                               bytearr[byteIndex++] = (byte)( ((utflen>>>13)&0xff) );  
+                                               bytearr[byteIndex++] = (byte)( ((lengthTester&0x1f) | 0xc0) );
+                                               bytearr[byteIndex++] = (byte)( ((lengthTester>>>5)&0xff) );
+                                               bytearr[byteIndex++] = (byte)( ((lengthTester>>>13)&0xff) );    
                                        }
                                        else {
-                                               utflen -= 0x200000;
-                                               if(utflen < 0x10000000) {
+                                               lengthTester -= 0x200000;
+                                               if(lengthTester < 0x10000000) {
                                                        bytearr = new byte[utflen+4];
-                                                       bytearr[byteIndex++] = (byte)( ((utflen&0x0f) | 0xe0) );
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>4)&0xff) );
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>12)&0xff) );  
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>20)&0xff) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester&0x0f) | 0xe0) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>4)&0xff) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>12)&0xff) );    
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>20)&0xff) );
                                                }
                                                else {
-                                                       utflen -= 0x10000000;
+                                                       lengthTester -= 0x10000000;
                                                        bytearr = new byte[utflen+5];
-                                                       bytearr[byteIndex++] = (byte)( ((utflen&0x07) | 0xf0) );
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>3)&0xff) );
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>11)&0xff) );  
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>19)&0xff) );
-                                                       bytearr[byteIndex++] = (byte)( ((utflen>>>27)&0xff) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester&0x07) | 0xf0) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>3)&0xff) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>11)&0xff) );    
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>19)&0xff) );
+                                                       bytearr[byteIndex++] = (byte)( ((lengthTester>>>27)&0xff) );
                                                }
                                        }                               
                                }