@Override protected Object readNull(Decoder decoder) throws IOException { return decoder.readNull(); }
@Override protected Object readNull(Decoder decoder) throws IOException { return decoder.readNull(); }
/** * Decode a map. */ static Map<String, String> decodeMap(Decoder decoder) throws IOException { ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); int len = decoder.readInt(); while (len != 0) { for (int i = 0; i < len; i++) { String key = decoder.readString(); String value = decoder.readInt() == 0 ? decoder.readString() : (String) decoder.readNull(); map.put(key, value); } len = decoder.readInt(); } return map.build(); }
/** * Decodes from the given {@link Decoder} to reconstruct a {@link StreamEventData}. * The set of headers provided is used as the default set of headers. * * @param decoder the decoder to read data from * @param defaultHeaders A map of headers available by default. * @return A new instance of {@link co.cask.cdap.api.stream.StreamEventData}. * @throws IOException If there is any IO error during decoding. */ public static StreamEventData decode(Decoder decoder, Map<String, String> defaultHeaders) throws IOException { // Reads the body ByteBuffer body = decoder.readBytes(); // Reads the headers int len = decoder.readInt(); // A special optimization for the case where there is no event header. if (len == 0) { return new StreamEventData(defaultHeaders, body); } Map<String, String> headers = defaultHeaders.isEmpty() ? Maps.<String, String>newHashMap() : Maps.newHashMap(defaultHeaders); do { for (int i = 0; i < len; i++) { String key = decoder.readString(); String value = decoder.readInt() == 0 ? decoder.readString() : (String) decoder.readNull(); headers.put(key, value); } len = decoder.readInt(); } while (len != 0); return new StreamEventData(headers, body); }
/** * Skips an encoded {@link co.cask.cdap.api.stream.StreamEventData}. * * @param decoder Decoder to skip data from. * @throws IOException If there is any IO error during decoding. */ public static void skip(Decoder decoder) throws IOException { // Skips the body decoder.skipBytes(); // Skips the headers int len = decoder.readInt(); while (len != 0) { for (int i = 0; i < len; i++) { decoder.skipString(); if (decoder.readInt() == 0) { decoder.skipString(); } else { decoder.readNull(); } } len = decoder.readInt(); } }
switch (schema.getType()) { case NULL: decoder.readNull(); return null; case BOOLEAN:
switch (schema.getType()) { case NULL: decoder.readNull(); return null; case BOOLEAN:
Assert.assertNull(decoder.readNull());