use of com.google.protobuf.UninitializedMessageException in project pulsar by yahoo.
the class MessageIdImpl method fromByteArray.
// / Serialization
public static MessageId fromByteArray(byte[] data) throws IOException {
checkNotNull(data);
ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length));
PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder();
PulsarApi.MessageIdData idData;
try {
idData = builder.mergeFrom(inputStream, null).build();
} catch (UninitializedMessageException e) {
throw new IOException(e);
}
MessageIdImpl messageId;
if (idData.hasBatchIndex()) {
messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex());
} else {
messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition());
}
inputStream.recycle();
builder.recycle();
idData.recycle();
return messageId;
}
use of com.google.protobuf.UninitializedMessageException in project graylog2-server by Graylog2.
the class RawMessage method encode.
public byte[] encode() {
try {
final JournalMessages.CodecInfo codec = msgBuilder.getCodec();
final JournalMessages.CodecInfo.Builder builder = JournalMessages.CodecInfo.newBuilder(codec);
final String codecConfigJson = codecConfig.serializeToJson();
if (codecConfigJson != null) {
builder.setConfig(codecConfigJson);
}
msgBuilder.setCodec(builder.build());
final JournalMessage journalMessage = msgBuilder.build();
return journalMessage.toByteArray();
} catch (UninitializedMessageException e) {
log.error("Unable to write RawMessage to journal because required fields are missing, " + "this message will be discarded. This is a bug.", e);
return null;
}
}
Aggregations