Skip to content

Commit 7280ed0

Browse files
committed
Upgrade generated sources for Colfer.
1 parent 2aee909 commit 7280ed0

File tree

3 files changed

+319
-262
lines changed

3 files changed

+319
-262
lines changed

tpc/pregen/media.colf/media.colf/serializers/colfer/media/Image.java

Lines changed: 91 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66

77
import static java.lang.String.format;
8+
import java.util.InputMismatchException;
89
import java.nio.BufferOverflowException;
910
import java.nio.BufferUnderflowException;
10-
import javax.xml.bind.TypeConstraintException;
11-
import javax.xml.bind.DataBindingException;
1211

1312

1413
/**
@@ -37,99 +36,104 @@ public class Image implements java.io.Serializable {
3736
/**
3837
* Serializes the object.
3938
* @param buf the data destination.
40-
* @param offset the first byte index.
41-
* @return the index of the first byte after the last byte written.
39+
* @param offset the initial index for {@code buf}, inclusive.
40+
* @return the final index for {@code buf}, exclusive.
4241
* @throws BufferOverflowException when {@code buf} is too small.
4342
* @throws IllegalStateException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}.
4443
*/
4544
public int marshal(byte[] buf, int offset) {
4645
int i = offset;
4746
try {
48-
4947
if (! this.uri.isEmpty()) {
5048
buf[i++] = (byte) 0;
51-
String s = this.uri;
52-
int sLength = s.length();
53-
5449
int start = ++i;
55-
for (int sIndex = 0; sIndex < sLength; sIndex++) {
50+
51+
String s = this.uri;
52+
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
5653
char c = s.charAt(sIndex);
57-
if (c < 128) {
54+
if (c < '\u0080') {
5855
buf[i++] = (byte) c;
59-
} else if (c < 2048) {
56+
} else if (c < '\u0800') {
6057
buf[i++] = (byte) (192 | c >>> 6);
6158
buf[i++] = (byte) (128 | c & 63);
62-
} else if (! Character.isSurrogate(c)) {
59+
} else if (c < '\ud800' || c > '\udfff') {
6360
buf[i++] = (byte) (224 | c >>> 12);
6461
buf[i++] = (byte) (128 | c >>> 6 & 63);
6562
buf[i++] = (byte) (128 | c & 63);
66-
} else if (++sIndex != sLength) {
67-
int cp = Character.toCodePoint(c, s.charAt(sIndex));
68-
buf[i++] = (byte) (240 | cp >>> 18);
69-
buf[i++] = (byte) (128 | cp >>> 12 & 63);
70-
buf[i++] = (byte) (128 | cp >>> 6 & 63);
71-
buf[i++] = (byte) (128 | cp & 63);
63+
} else {
64+
int cp = 0;
65+
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
66+
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
67+
buf[i++] = (byte) (240 | cp >>> 18);
68+
buf[i++] = (byte) (128 | cp >>> 12 & 63);
69+
buf[i++] = (byte) (128 | cp >>> 6 & 63);
70+
buf[i++] = (byte) (128 | cp & 63);
71+
} else
72+
buf[i++] = (byte) '?';
7273
}
7374
}
74-
7575
int size = i - start;
7676
if (size > colferSizeMax)
7777
throw new IllegalStateException(format("colfer: field serializers/colfer/media.image.uri size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
7878

79-
int shift = 0;
80-
for (int x = size; (x & ~((1 << 7) - 1)) != 0; x >>>= 7) shift++;
81-
if (shift != 0) System.arraycopy(buf, start, buf, start + shift, size);
82-
i = start + shift + size;
79+
int ii = start - 1;
80+
if (size > 0x7f) {
81+
i++;
82+
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
83+
System.arraycopy(buf, start, buf, i - size, size);
8384

84-
start--;
85-
while ((size & ~((1 << 7) - 1)) != 0) {
86-
buf[start++] = (byte) (size | 0x80);
87-
size >>>= 7;
85+
do {
86+
buf[ii++] = (byte) (size | 0x80);
87+
size >>>= 7;
88+
} while (size > 0x7f);
8889
}
89-
buf[start++] = (byte) size;
90+
buf[ii] = (byte) size;
9091
}
9192

9293
if (! this.title.isEmpty()) {
9394
buf[i++] = (byte) 1;
94-
String s = this.title;
95-
int sLength = s.length();
96-
9795
int start = ++i;
98-
for (int sIndex = 0; sIndex < sLength; sIndex++) {
96+
97+
String s = this.title;
98+
for (int sIndex = 0, sLength = s.length(); sIndex < sLength; sIndex++) {
9999
char c = s.charAt(sIndex);
100-
if (c < 128) {
100+
if (c < '\u0080') {
101101
buf[i++] = (byte) c;
102-
} else if (c < 2048) {
102+
} else if (c < '\u0800') {
103103
buf[i++] = (byte) (192 | c >>> 6);
104104
buf[i++] = (byte) (128 | c & 63);
105-
} else if (! Character.isSurrogate(c)) {
105+
} else if (c < '\ud800' || c > '\udfff') {
106106
buf[i++] = (byte) (224 | c >>> 12);
107107
buf[i++] = (byte) (128 | c >>> 6 & 63);
108108
buf[i++] = (byte) (128 | c & 63);
109-
} else if (++sIndex != sLength) {
110-
int cp = Character.toCodePoint(c, s.charAt(sIndex));
111-
buf[i++] = (byte) (240 | cp >>> 18);
112-
buf[i++] = (byte) (128 | cp >>> 12 & 63);
113-
buf[i++] = (byte) (128 | cp >>> 6 & 63);
114-
buf[i++] = (byte) (128 | cp & 63);
109+
} else {
110+
int cp = 0;
111+
if (++sIndex < sLength) cp = Character.toCodePoint(c, s.charAt(sIndex));
112+
if ((cp >= 1 << 16) && (cp < 1 << 21)) {
113+
buf[i++] = (byte) (240 | cp >>> 18);
114+
buf[i++] = (byte) (128 | cp >>> 12 & 63);
115+
buf[i++] = (byte) (128 | cp >>> 6 & 63);
116+
buf[i++] = (byte) (128 | cp & 63);
117+
} else
118+
buf[i++] = (byte) '?';
115119
}
116120
}
117-
118121
int size = i - start;
119122
if (size > colferSizeMax)
120123
throw new IllegalStateException(format("colfer: field serializers/colfer/media.image.title size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
121124

122-
int shift = 0;
123-
for (int x = size; (x & ~((1 << 7) - 1)) != 0; x >>>= 7) shift++;
124-
if (shift != 0) System.arraycopy(buf, start, buf, start + shift, size);
125-
i = start + shift + size;
125+
int ii = start - 1;
126+
if (size > 0x7f) {
127+
i++;
128+
for (int x = size; x >= 1 << 14; x >>>= 7) i++;
129+
System.arraycopy(buf, start, buf, i - size, size);
126130

127-
start--;
128-
while ((size & ~((1 << 7) - 1)) != 0) {
129-
buf[start++] = (byte) (size | 0x80);
130-
size >>>= 7;
131+
do {
132+
buf[ii++] = (byte) (size | 0x80);
133+
size >>>= 7;
134+
} while (size > 0x7f);
131135
}
132-
buf[start++] = (byte) size;
136+
buf[ii] = (byte) size;
133137
}
134138

135139
if (this.width != 0) {
@@ -139,7 +143,7 @@ public int marshal(byte[] buf, int offset) {
139143
buf[i++] = (byte) (2 | 0x80);
140144
} else
141145
buf[i++] = (byte) 2;
142-
while ((x & ~((1 << 7) - 1)) != 0) {
146+
while ((x & ~0x7f) != 0) {
143147
buf[i++] = (byte) (x | 0x80);
144148
x >>>= 7;
145149
}
@@ -153,7 +157,7 @@ public int marshal(byte[] buf, int offset) {
153157
buf[i++] = (byte) (3 | 0x80);
154158
} else
155159
buf[i++] = (byte) 3;
156-
while ((x & ~((1 << 7) - 1)) != 0) {
160+
while ((x & ~0x7f) != 0) {
157161
buf[i++] = (byte) (x | 0x80);
158162
x >>>= 7;
159163
}
@@ -175,50 +179,53 @@ public int marshal(byte[] buf, int offset) {
175179
throw new IllegalStateException(format("colfer: serial exceeds %d bytes", colferSizeMax));
176180
if (i >= buf.length)
177181
throw new BufferOverflowException();
178-
throw new RuntimeException("colfer: bug", e);
182+
throw e;
179183
}
180184
}
181185

182186
/**
183187
* Deserializes the object.
184188
* @param buf the data source.
185-
* @param offset the first byte index.
186-
* @return the index of the first byte after the last byte read.
189+
* @param offset the initial index for {@code buf}, inclusive.
190+
* @return the final index for {@code buf}, exclusive.
187191
* @throws BufferUnderflowException when {@code buf} is incomplete. (EOF)
188-
* @throws TypeConstraintException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}.
189-
* @throws DataBindingException when the data does not match this object's schema.
192+
* @throws SecurityException on an upper limit breach defined by either {@link #colferSizeMax} or {@link #colferListMax}.
193+
* @throws InputMismatchException when the data does not match this object's schema.
190194
*/
191-
public int unmarshal(byte[] buf, int offset)
192-
throws BufferUnderflowException, TypeConstraintException, DataBindingException {
195+
public int unmarshal(byte[] buf, int offset) {
193196
int i = offset;
194197
try {
195198
byte header = buf[i++];
196199

197200
if (header == (byte) 0) {
198-
int n = 0;
201+
int size = 0;
199202
for (int shift = 0; true; shift += 7) {
200203
byte b = buf[i++];
201-
n |= (b & 0x7f) << shift;
204+
size |= (b & 0x7f) << shift;
202205
if (shift == 28 || b >= 0) break;
203206
}
204-
if (n > colferSizeMax)
205-
throw new TypeConstraintException(format("colfer: field serializers/colfer/media.image.uri size %d exceeds %d UTF-8 bytes", n, colferSizeMax));
206-
this.uri = new String(buf, i, n, this._utf8);
207-
i += n;
207+
if (size > colferSizeMax)
208+
throw new SecurityException(format("colfer: field serializers/colfer/media.image.uri size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
209+
210+
int start = i;
211+
i += size;
212+
this.uri = new String(buf, start, size, this._utf8);
208213
header = buf[i++];
209214
}
210215

211216
if (header == (byte) 1) {
212-
int n = 0;
217+
int size = 0;
213218
for (int shift = 0; true; shift += 7) {
214219
byte b = buf[i++];
215-
n |= (b & 0x7f) << shift;
220+
size |= (b & 0x7f) << shift;
216221
if (shift == 28 || b >= 0) break;
217222
}
218-
if (n > colferSizeMax)
219-
throw new TypeConstraintException(format("colfer: field serializers/colfer/media.image.title size %d exceeds %d UTF-8 bytes", n, colferSizeMax));
220-
this.title = new String(buf, i, n, this._utf8);
221-
i += n;
223+
if (size > colferSizeMax)
224+
throw new SecurityException(format("colfer: field serializers/colfer/media.image.title size %d exceeds %d UTF-8 bytes", size, colferSizeMax));
225+
226+
int start = i;
227+
i += size;
228+
this.title = new String(buf, start, size, this._utf8);
222229
header = buf[i++];
223230
}
224231

@@ -273,15 +280,17 @@ public int unmarshal(byte[] buf, int offset)
273280
}
274281

275282
if (header != (byte) 0x7f)
276-
throw new DataBindingException(format("colfer: unknown header at byte %d", i - 1), null);
283+
throw new InputMismatchException(format("colfer: unknown header at byte %d", i - 1));
277284
} catch (IndexOutOfBoundsException e) {
278285
if (i - offset > colferSizeMax)
279-
throw new TypeConstraintException(format("colfer: serial exceeds %d bytes", colferSizeMax));
286+
throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
280287
if (i >= buf.length)
281288
throw new BufferUnderflowException();
282289
throw new RuntimeException("colfer: bug", e);
283290
}
284291

292+
if (i - offset > colferSizeMax)
293+
throw new SecurityException(format("colfer: serial exceeds %d bytes", colferSizeMax));
285294
return i;
286295
}
287296

@@ -335,7 +344,14 @@ public void setLarge(boolean value) {
335344

336345
@Override
337346
public final int hashCode() {
338-
return java.util.Objects.hash(0x7f, uri, title, width, height, small, large);
347+
int h = 1;
348+
if (this.uri != null) h = 31 * h + this.uri.hashCode();
349+
if (this.title != null) h = 31 * h + this.title.hashCode();
350+
h = 31 * h + this.width;
351+
h = 31 * h + this.height;
352+
h = 31 * h + (this.small ? 1231 : 1237);
353+
h = 31 * h + (this.large ? 1231 : 1237);
354+
return h;
339355
}
340356

341357
@Override

0 commit comments

Comments
 (0)