Search in sources :

Example 1 with UninitializedMessageException

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;
}
Also used : UninitializedMessageException(com.google.protobuf.UninitializedMessageException) MessageIdData(com.yahoo.pulsar.common.api.proto.PulsarApi.MessageIdData) MessageIdData(com.yahoo.pulsar.common.api.proto.PulsarApi.MessageIdData) ByteBufCodedInputStream(com.yahoo.pulsar.common.util.protobuf.ByteBufCodedInputStream) PulsarApi(com.yahoo.pulsar.common.api.proto.PulsarApi) IOException(java.io.IOException)

Example 2 with UninitializedMessageException

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;
    }
}
Also used : UninitializedMessageException(com.google.protobuf.UninitializedMessageException) JournalMessage(org.graylog2.plugin.journal.JournalMessages.JournalMessage) ByteString(com.google.protobuf.ByteString)

Aggregations

UninitializedMessageException (com.google.protobuf.UninitializedMessageException)2 ByteString (com.google.protobuf.ByteString)1 PulsarApi (com.yahoo.pulsar.common.api.proto.PulsarApi)1 MessageIdData (com.yahoo.pulsar.common.api.proto.PulsarApi.MessageIdData)1 ByteBufCodedInputStream (com.yahoo.pulsar.common.util.protobuf.ByteBufCodedInputStream)1 IOException (java.io.IOException)1 JournalMessage (org.graylog2.plugin.journal.JournalMessages.JournalMessage)1