From 03054ec8e3a714450198c20f9dae266246ec9193 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 7 Apr 2012 05:37:05 +0000 Subject: [PATCH] Allow null for input/output strings and chars. Rearrange JARs. --- .classpath | 6 +++--- build/minlog-1.2.jar | Bin 0 -> 3085 bytes build/minlog-none-1.2.jar | Bin 0 -> 2788 bytes lib/{ => optional}/asm-3.3.1.jar | Bin lib/{ => optional}/reflectasm-1.01.jar | Bin project.yaml | 7 ++----- src/com/esotericsoftware/kryo/io/Input.java | 16 ++++++++++++++-- src/com/esotericsoftware/kryo/io/Output.java | 17 ++++++++++++----- .../esotericsoftware/kryo/InputOutputTest.java | 4 ++++ 9 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 build/minlog-1.2.jar create mode 100644 build/minlog-none-1.2.jar rename lib/{ => optional}/asm-3.3.1.jar (100%) rename lib/{ => optional}/reflectasm-1.01.jar (100%) diff --git a/.classpath b/.classpath index 7c5308359..333c64934 100644 --- a/.classpath +++ b/.classpath @@ -4,8 +4,8 @@ - - - + + + diff --git a/build/minlog-1.2.jar b/build/minlog-1.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..7cc55acf7fb1e72042ad38969af6bdfc8ce6b563 GIT binary patch literal 3085 zcmai03pAAJAD(iT$#se_E^8=Lm?b21Xx*7Gm|Su|L#lKT@=Y( z3^PTE#wC@zF_T-1akuPD?Z4X2+I`;ho%5de{GR9geZTLV=Y1^A*w{q?+|0Eef!79n z1s(u9z{0>r@01DLPNqt($<*SciA7&=Qoh88as~Q1VBqN0CP| zN@k8gLuVj!=;eT=fCC>JIai?_Z^V2J>tQv*`?0BSzk;24>Vd;5?_UA>tHLV~7vvRy z_6WqGfc32p`QE?ra8`Aj`?_d1t@u3b_)!QwHd>`wGr9% z6DC(I84h_4Hzl8r4Jxs3OayYvjTBf=?pVLMgX-=Q&BO$xB?K7?>k5fYAks%@KpGoy=`1fLi@D+0_2n} z<+-mf=>f1hd!!ek<>5%%6tZt=sxtP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E0r;_hu=o z1~xLv3`geJltaL?Q1hu|_DwaaYN_}3v^DHZ7tI{A{tT;^SGLoDXWO1mmyY`1vMjai z4)ED&SMOTEF{n$)jy%=-^;Bs@V)LtfhF{?nCI}}3MrQT7^wl42P69Wfd#h#C9*Vz6 z%oFN;Oc;gH>jlc!P__pf%xf<9uIxEqLD}dd33deM+f9bqKIUr;rVPm#Ugx*><_93N zVm7}Y^SsNumM{oZ3(Csutyof0Esere|=1nmFwt3~14Mf^$lfVa`2B z_#bif$IRnetKqqjA6hl;jh}w12-;!mLB2gc`O$wx%?OVPuo1XCK5DKlOJJ_bNJ)f{{+o6@(cg~ literal 0 HcmV?d00001 diff --git a/build/minlog-none-1.2.jar b/build/minlog-none-1.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..50bd8d2cd2368c55b45fe40e76243207d85db349 GIT binary patch literal 2788 zcmai$2T+sQ7RMu@7crp)rASFoN&rzo4frC0bR(dEpg^dh#ZW_U20{^a0jVn@JP}wS z2n!NWHza^kMViuEBqAuCSXN)6`$QdC&o_7G%$@T;-}&x0_dh?BDUeeXz{`5vB0~{? zZ-NiN2{1RXMyeTG7^;740|0;klqnA{yMp7NGSrr0QC7uQu{qMh*wDbr8g6d5V&2hi zW~v775i(U%?&|2Sw$$j;nxOl`P0Uq|&3l5%IQg<)O44@a?)Bu%da;-34wIlu*obEp zzYtf!zkt5NEc-9{Z~HvR(F#Q33D#@ai#-Vc=b<(tzW)kN)~*ZISAFXWv41Mu0CN zK1G=)2YunHA9nC^?>sh@b&(03;DRxMc>R3u5@p{K^yAs6jr^6-fXD~0!rvFo4`n>;|*ywMEUr;PS1oqo|aup zC3pP=gB+tKV002897(Y*f|UFNC$EMp30W0*4a^2M6nFMN61i=6Iw3x(X~u2=s&=}! z!^^9sN~k(_^oiAB7yH?_V7mv6BqLm+vo~5dsg*8Sjm|2kabe|+ zPM(r`xO)2*9L&Aj?SM-ddI-OxxD?; zsF?On+SO*w{g9TCOJvXtJ)tOF#p%FX z{bbRaEbAO4x#L!V#X;lh3~ipK$54{1fONGf?>*kJm<#@xannhD4!Y61NE6rmy#PHrpP zk?G)5SfxUpJrx=m*C7%%wyI8=9(xUlDwHnNK8bC4zk7ED|L7>ZiLR|-q%lR+i?fe} zKp|^#VvMnt$qBXj8)&5u==c$X!iA4IGeQ)5ohNZ~(Q|33H@WQ@Ij1wB^MN?ot8N8< zD8qy68T8^}<$J_>hCOChg#ith<|i7ctWEop`^G7I{GOg3ItF_4RQSD2*CenpSs1rX zc2Zui#VsOkaB1&YlZPVB7ad`dPlz1Lt83cZjofK(LZ!1cQj)~4#>hvx(ZNTZ&RF7*HY`i#9 zsWm(v9rb}D24jno;|#gU46-3;bR;-i5N<$bsaMcD+U)w3>m+G+Z#`b9DLk}21aiB+ zBMerTqduc0XnPH5Gqg|IMr$;v^Y#)zTv(IwhgA-`3MDG{-<*3@)*UHEB+17wZ20BD zp0`HZRVzm&3e((gTRWI|94Bg`1Rt~tNtGhVcvV;o5+&M-w5DN{;}z&rX{jw~;QHi0 z^JdcM{`QqR1GNp6&k^8+Ps&W?cG- zdUy4FK_E!>$Qipi{@0IaNbNec5vsWQV3`iN_6%jy)e=j)sj7r8l(Fkr7-=vB3^YlxpJ9|3r|ah2KpGgSr*2$KZtF;EW{f zlb&Q&v3>*xOjqd5qBm2dsUnONBU@|y?7;JG8#y17T2Ha6;*nvkrs6SG){9^FuhMdjNWu;%G-yjdW z13zGEI@#>d!b-oe%GL@tt!xH^m9iB-VVA92u<2zpc5U0D#aEX3{_MVWD>lt+#_3;l r`jKsZJlb#n7~AbO<1*L3&&cZh#rsgETr3j>0C-r>OV&8_&$#+OM2|)~ literal 0 HcmV?d00001 diff --git a/lib/asm-3.3.1.jar b/lib/optional/asm-3.3.1.jar similarity index 100% rename from lib/asm-3.3.1.jar rename to lib/optional/asm-3.3.1.jar diff --git a/lib/reflectasm-1.01.jar b/lib/optional/reflectasm-1.01.jar similarity index 100% rename from lib/reflectasm-1.01.jar rename to lib/optional/reflectasm-1.01.jar diff --git a/project.yaml b/project.yaml index 8ce946bb8..6da5efea1 100644 --- a/project.yaml +++ b/project.yaml @@ -1,7 +1,4 @@ -version: 2.01 -dependencies: -- ../reflectasm -- ../minlog +version: 2.02 --- Build.build(project); -Build.oneJAR(project); +Build.oneJAR(project); \ No newline at end of file diff --git a/src/com/esotericsoftware/kryo/io/Input.java b/src/com/esotericsoftware/kryo/io/Input.java index 4b5bbec54..f646ee28b 100644 --- a/src/com/esotericsoftware/kryo/io/Input.java +++ b/src/com/esotericsoftware/kryo/io/Input.java @@ -344,7 +344,13 @@ public boolean canReadInt () throws KryoException { /** Reads the length and string of 8 bit characters. */ public String readChars () throws KryoException { int charCount = readInt(true); - if (charCount == 0) return ""; + switch (charCount) { + case 0: + return null; + case 1: + return ""; + } + charCount--; if (chars.length < charCount) chars = new char[charCount]; if (charCount > require(1, charCount)) return readChars_slow(charCount); char[] chars = this.chars; @@ -368,7 +374,13 @@ private String readChars_slow (int charCount) { /** Reads the length and string of UTF8 characters. */ public String readString () throws KryoException { int charCount = readInt(true); - if (charCount == 0) return ""; + switch (charCount) { + case 0: + return null; + case 1: + return ""; + } + charCount--; if (chars.length < charCount) chars = new char[charCount]; char[] chars = this.chars; byte[] buffer = this.buffer; diff --git a/src/com/esotericsoftware/kryo/io/Output.java b/src/com/esotericsoftware/kryo/io/Output.java index 5b1e812e5..e7ba5ac97 100644 --- a/src/com/esotericsoftware/kryo/io/Output.java +++ b/src/com/esotericsoftware/kryo/io/Output.java @@ -232,9 +232,12 @@ else if ((value >>> 21 & ~0x7F) == 0) /** Writes the length and string using 1 byte per character. */ public void writeChars (String value) throws KryoException { - if (value == null) throw new IllegalArgumentException("value cannot be null."); + if (value == null) { + writeByte(0); + return; + } int charCount = value.length(); - writeInt(charCount, true); + writeInt(charCount + 1, true); if (capacity < charCount) writeChars_slow(value, charCount); else { @@ -257,11 +260,15 @@ private void writeChars_slow (String value, int charCount) throws KryoException } } - /** Writes the length and string using UTF8. */ + /** Writes the length and string using UTF8, or null. + * @param value May be null. */ public void writeString (String value) throws KryoException { - if (value == null) throw new IllegalArgumentException("value cannot be null."); + if (value == null) { + writeByte(0); + return; + } int charCount = value.length(); - writeInt(charCount, true); + writeInt(charCount + 1, true); int charIndex = 0; if (capacity >= charCount) { // Try to write 8 bit chars. diff --git a/test/com/esotericsoftware/kryo/InputOutputTest.java b/test/com/esotericsoftware/kryo/InputOutputTest.java index 465ac05e4..2b32ccb05 100644 --- a/test/com/esotericsoftware/kryo/InputOutputTest.java +++ b/test/com/esotericsoftware/kryo/InputOutputTest.java @@ -87,22 +87,26 @@ public void runUTFTest (Output write) throws IOException { write.writeString("uno"); write.writeString("dos"); write.writeString("tres"); + write.writeString(null); write.writeString(value1); write.writeString(value2); write.writeChars("uno"); write.writeChars("dos"); write.writeChars("tres"); + write.writeChars(null); write.writeChars(value1); Input read = new Input(write.toBytes()); assertEquals("uno", read.readString()); assertEquals("dos", read.readString()); assertEquals("tres", read.readString()); + assertEquals(null, read.readString()); assertEquals(value1, read.readString()); assertEquals(value2, read.readString()); assertEquals("uno", read.readChars()); assertEquals("dos", read.readChars()); assertEquals("tres", read.readChars()); + assertEquals(null, read.readChars()); assertEquals(value1, read.readChars()); }