@Override public void validate(byte[] message) { if (message.length != 8) { throw new SchemaSerializationException("Size of data received by LongSchema is not 8"); } }
builder.value(rawPayload); } catch (SchemaSerializationException e) { sendAckResponse(new ProducerAck(PayloadEncodingError, e.getMessage(), null, requestContext)); return;
@Override public void validate(byte[] message) { if (message.length != 2) { throw new SchemaSerializationException("Size of data received by ShortSchema is not 2"); } }
@Override public void validate(byte[] message) { if (message.length != 1) { throw new SchemaSerializationException("Size of data received by ByteSchema is not 1"); } }
@Override public void validate(byte[] message) { if (message.length != 8) { throw new SchemaSerializationException("Size of data received by DoubleSchema is not 8"); } }
@Override public void validate(byte[] message) { if (message.length != 4) { throw new SchemaSerializationException("Size of data received by FloatSchema is not 4"); } }
@Override public void validate(byte[] message) { if (message.length != 1) { throw new SchemaSerializationException("Size of data received by BooleanSchema is not 1"); } }
@Override public void validate(byte[] message) { if (message.length != 4) { throw new SchemaSerializationException("Size of data received by IntSchema is not 4"); } }
@Override public byte[] encode(T message) throws SchemaSerializationException { try { return objectMapper.writeValueAsBytes(message); } catch (JsonProcessingException e) { throw new SchemaSerializationException(e); } }
@Override public T decode(byte[] bytes) { try { return this.tParser.parseFrom(bytes); } catch (Exception e) { throw new RuntimeException(new SchemaSerializationException(e)); } }
@Override public T decode(byte[] bytes) { try { return objectMapper.readValue(bytes, this.pojo); } catch (IOException e) { throw new SchemaSerializationException(e); } }
@Override public byte[] encode(GenericRecord message) { checkArgument(message instanceof GenericAvroRecord); GenericJsonRecord gjr = (GenericJsonRecord) message; try { return objectMapper.writeValueAsBytes(gjr.getJsonNode().toString()); } catch (IOException ioe) { throw new SchemaSerializationException(ioe); } }
@Override public GenericRecord decode(byte[] bytes) { try { JsonNode jn = objectMapper.readTree(new String(bytes, UTF_8)); return new GenericJsonRecord(fields, jn); } catch (IOException ioe) { throw new SchemaSerializationException(ioe); } } }
@Override public synchronized byte[] encode(T message) { try { datumWriter.write(message, this.encoder); this.encoder.flush(); return this.byteArrayOutputStream.toByteArray(); } catch (Exception e) { throw new SchemaSerializationException(e); } finally { this.byteArrayOutputStream.reset(); } }
@Override public T decode(byte[] bytes) { try { BinaryDecoder decoderFromCache = decoders.get(); BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(bytes, decoderFromCache); if (decoderFromCache == null) { decoders.set(decoder); } return reader.read(null, DecoderFactory.get().binaryDecoder(bytes, decoder)); } catch (IOException e) { throw new SchemaSerializationException(e); } }
@Override public synchronized byte[] encode(GenericRecord message) { checkArgument(message instanceof GenericAvroRecord); GenericAvroRecord gar = (GenericAvroRecord) message; try { datumWriter.write(gar.getAvroRecord(), this.encoder); this.encoder.flush(); return this.byteArrayOutputStream.toByteArray(); } catch (Exception e) { throw new SchemaSerializationException(e); } finally { this.byteArrayOutputStream.reset(); } }
@Override public GenericRecord decode(byte[] bytes) { try { Decoder decoder = DecoderFactory.get().binaryDecoder(bytes, null); org.apache.avro.generic.GenericRecord avroRecord = datumReader.read( null, decoder); return new GenericAvroRecord(schema, fields, avroRecord); } catch (IOException e) { throw new SchemaSerializationException(e); } }
@Override public void validate(byte[] message) { if (message.length != 2) { throw new SchemaSerializationException("Size of data received by ShortSchema is not 2"); } }
@Override public void validate(byte[] message) { if (message.length != 4) { throw new SchemaSerializationException("Size of data received by IntSchema is not 4"); } }
@Override public void validate(byte[] message) { if (message.length != 4) { throw new SchemaSerializationException("Size of data received by FloatSchema is not 4"); } }