private byte[] encode(Iterable<T> values, IterableCoder<T> coder) { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { coder.encode(values, stream, Coder.Context.OUTER); return stream.toByteArray(); } catch (IOException ex) { throw new RuntimeException(ex); } }
public ValuesSource(Iterable<T> values, Coder<T> coder) { this.iterableCoder = IterableCoder.of(coder); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { iterableCoder.encode(values, bos, Context.OUTER); } catch (IOException ex) { throw new RuntimeException(ex); } this.codedValues = bos.toByteArray(); }
@Override @SuppressWarnings("unchecked") public void encode(CoGbkResult value, OutputStream outStream) throws CoderException, IOException { if (!schema.equals(value.getSchema())) { throw new CoderException("input schema does not match coder schema"); } if (schema.size() == 0) { return; } for (int unionTag = 0; unionTag < schema.size(); unionTag++) { tagListCoder(unionTag).encode(value.valueMap.get(unionTag), outStream); } }
@Override public void encode(KafkaRecord<K, V> value, OutputStream outStream) throws IOException { stringCoder.encode(value.getTopic(), outStream); intCoder.encode(value.getPartition(), outStream); longCoder.encode(value.getOffset(), outStream); longCoder.encode(value.getTimestamp(), outStream); intCoder.encode(value.getTimestampType().ordinal(), outStream); headerCoder.encode(toIterable(value), outStream); kvCoder.encode(value.getKV(), outStream); }
@Override public void encode(KafkaRecord<K, V> value, OutputStream outStream) throws IOException { stringCoder.encode(value.getTopic(), outStream); intCoder.encode(value.getPartition(), outStream); longCoder.encode(value.getOffset(), outStream); longCoder.encode(value.getTimestamp(), outStream); intCoder.encode(value.getTimestampType().ordinal(), outStream); headerCoder.encode(toIterable(value), outStream); kvCoder.encode(value.getKV(), outStream); }