@Override protected String readString(Decoder decoder) throws IOException { return decoder.readString(); }
@Override protected String readString(Decoder decoder) throws IOException { return decoder.readString(); }
/** * 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); }
return decoder.readBytes(); case STRING: return decoder.readString(); case ENUM: return decodeEnum(decoder, schema);
return decoder.readBytes(); case STRING: return decoder.readString(); case ENUM: return decodeEnum(decoder, schema);
Assert.assertEquals("This is a testing message", decoder.readString()); String str = Character.toString((char) 200) + Character.toString((char) 20000) + Character.toString((char) 40000); encoder.writeString(str); Assert.assertEquals(str, decoder.readString());