From fb2f890caf6406f83c2598c28519da7bfee57644 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 15 Feb 2018 11:05:53 +0200 Subject: [PATCH] Add support for strings that are longer than 127 characters refs #7770 Change-Id: I60990b0f3a0c8051abc43b824df1a88afc07bc87 --- .../simantics/db/common/WriteBindings.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java index ef1ced835..e9ecce63c 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/WriteBindings.java @@ -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) ); } } } -- 2.47.1