-
Notifications
You must be signed in to change notification settings - Fork 1
/
KafkaCryptoMessage.java
35 lines (29 loc) · 1.06 KB
/
KafkaCryptoMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.kafkacrypto;
import org.kafkacrypto.msgs.KafkaCryptoWireMessage;
import org.kafkacrypto.msgs.KafkaPlainWireMessage;
import org.kafkacrypto.exceptions.KafkaCryptoMessageException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public interface KafkaCryptoMessage
{
static final Logger _logger = LoggerFactory.getLogger("kafkacrypto-java.kafkacryptomessage");
public boolean isCleartext();
public boolean isCleartext(boolean retry);
public byte[] getMessage() throws KafkaCryptoMessageException;
public byte[] toWire() throws IOException;
public static KafkaCryptoMessage fromWire(byte[] wire)
{
if (wire == null || wire.length < 1) return null;
byte[][] msgs = Utils.splitArray(wire,1);
try {
if (msgs[0][0] == 1)
return new KafkaCryptoWireMessage().unpackb(msgs[1]);
if (msgs[0][0] == 0)
return new KafkaPlainWireMessage().unpackb(msgs[1]);
} catch (IOException ioe) {
KafkaCryptoMessage._logger.info("Error unpacking message", ioe);
}
return null;
}
}