kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | eb582d920b5cf819f51b389eed6304e8642003a3a1748c7f40b6869c63294179 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-12-10 15:37 +01:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-12-10 16:15 +01:00 |
| Parents | 7b1ae1faf58c |
1 file changed
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +27 −21
| @@ -2062,8 +2062,7 @@ | ||
| 2062 | 2062 | protected final UserType definition; |
| 2063 | 2063 | |
| 2064 | 2064 | protected AbstractUDTCodec(UserType definition, Class<T> javaClass) { |
| 2065 | - super(definition, javaClass); | |
| 2066 | - this.definition = definition; | |
| 2065 | + this(definition, TypeToken.of(javaClass)); | |
| 2067 | 2066 | } |
| 2068 | 2067 | |
| 2069 | 2068 | protected AbstractUDTCodec(UserType definition, TypeToken<T> javaType) { |
| @@ -2101,16 +2100,20 @@ | ||
| 2101 | 2100 | if (bytes == null) |
| 2102 | 2101 | return null; |
| 2103 | 2102 | // empty byte buffers will result in empty values |
| 2104 | - ByteBuffer input = bytes.duplicate(); | |
| 2105 | - T value = newInstance(); | |
| 2106 | - for (UserType.Field field : definition) { | |
| 2107 | - if (!input.hasRemaining()) | |
| 2108 | - break; | |
| 2109 | - int n = input.getInt(); | |
| 2110 | - ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n); | |
| 2111 | - value = deserializeAndSetField(element, value, Metadata.escapeId(field.getName()), protocolVersion); | |
| 2103 | + try { | |
| 2104 | + ByteBuffer input = bytes.duplicate(); | |
| 2105 | + T value = newInstance(); | |
| 2106 | + for (UserType.Field field : definition) { | |
| 2107 | + if (!input.hasRemaining()) | |
| 2108 | + break; | |
| 2109 | + int n = input.getInt(); | |
| 2110 | + ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n); | |
| 2111 | + value = deserializeAndSetField(element, value, Metadata.escapeId(field.getName()), protocolVersion); | |
| 2112 | + } | |
| 2113 | + return value; | |
| 2114 | + } catch (BufferUnderflowException e) { | |
| 2115 | + throw new InvalidTypeException("Not enough bytes to deserialize a UDT", e); | |
| 2112 | 2116 | } |
| 2113 | - return value; | |
| 2114 | 2117 | } |
| 2115 | 2118 | |
| 2116 | 2119 | @Override |
| @@ -2307,8 +2310,7 @@ | ||
| 2307 | 2310 | protected final TupleType definition; |
| 2308 | 2311 | |
| 2309 | 2312 | protected AbstractTupleCodec(TupleType definition, Class<T> javaClass) { |
| 2310 | - super(definition, javaClass); | |
| 2311 | - this.definition = definition; | |
| 2313 | + this(definition, TypeToken.of(javaClass)); | |
| 2312 | 2314 | } |
| 2313 | 2315 | |
| 2314 | 2316 | protected AbstractTupleCodec(TupleType definition, TypeToken<T> javaType) { |
| @@ -2351,15 +2353,19 @@ | ||
| 2351 | 2353 | if (bytes == null) |
| 2352 | 2354 | return null; |
| 2353 | 2355 | // empty byte buffers will result in empty values |
| 2354 | - ByteBuffer input = bytes.duplicate(); | |
| 2355 | - T value = newInstance(); | |
| 2356 | - int i = 0; | |
| 2357 | - while (input.hasRemaining() && i < definition.getComponentTypes().size()) { | |
| 2358 | - int n = input.getInt(); | |
| 2359 | - ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n); | |
| 2360 | - value = deserializeAndSetField(element, value, i++, protocolVersion); | |
| 2356 | + try { | |
| 2357 | + ByteBuffer input = bytes.duplicate(); | |
| 2358 | + T value = newInstance(); | |
| 2359 | + int i = 0; | |
| 2360 | + while (input.hasRemaining() && i < definition.getComponentTypes().size()) { | |
| 2361 | + int n = input.getInt(); | |
| 2362 | + ByteBuffer element = n < 0 ? null : CodecUtils.readBytes(input, n); | |
| 2363 | + value = deserializeAndSetField(element, value, i++, protocolVersion); | |
| 2364 | + } | |
| 2365 | + return value; | |
| 2366 | + } catch (BufferUnderflowException e) { | |
| 2367 | + throw new InvalidTypeException("Not enough bytes to deserialize a tuple", e); | |
| 2361 | 2368 | } |
| 2362 | - return value; | |
| 2363 | 2369 | } |
| 2364 | 2370 | |
| 2365 | 2371 | @Override |