/** * Check if the message is a valid object for this schema. * * <p>The implementation can choose what its most efficient approach to validate the schema. * If the implementation doesn't provide it, it will attempt to use {@link #decode(byte[])} * to see if this schema can decode this message or not as a validation mechanism to verify * the bytes. * * @param message the messages to verify * @return true if it is a valid message * @throws SchemaSerializationException if it is not a valid message */ default void validate(byte[] message) { decode(message); }
public KeyValue<K, V> decode(byte[] bytes) { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); int keyLength = byteBuffer.getInt(); byte[] keyBytes = new byte[keyLength]; byteBuffer.get(keyBytes); int valueLength = byteBuffer.getInt(); byte[] valueBytes = new byte[valueLength]; byteBuffer.get(valueBytes); return new KeyValue<>(keySchema.decode(keyBytes), valueSchema.decode(valueBytes)); }
@Override public GenericRecord decode(byte[] bytes) { ensureSchemaInitialized(); return schema.decode(bytes); }
@Override public byte[] decode(byte[] bytes) { ensureSchemaInitialized(); if (requireSchemaValidation) { // verify the message can be detected by the underlying schema schema.decode(bytes); } return bytes; }
@Override public T getValue() { return schema.decode(getData()); }
/** * Check if the message is a valid object for this schema. * * <p>The implementation can choose what its most efficient approach to validate the schema. * If the implementation doesn't provide it, it will attempt to use {@link #decode(byte[])} * to see if this schema can decode this message or not as a validation mechanism to verify * the bytes. * * @param message the messages to verify * @return true if it is a valid message * @throws SchemaSerializationException if it is not a valid message */ default void validate(byte[] message) { decode(message); }
@Override public GenericRecord decode(byte[] bytes) { ensureSchemaInitialized(); return schema.decode(bytes); }
@Override public byte[] decode(byte[] bytes) { ensureSchemaInitialized(); if (requireSchemaValidation) { // verify the message can be detected by the underlying schema schema.decode(bytes); } return bytes; }
@Override public T getValue() { return schema.decode(getData()); }