All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yamcs.ygw.ProtoBufUtils Maven / Gradle / Ivy

The newest version!
package org.yamcs.ygw;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import us.hebi.quickbuf.InvalidProtocolBufferException;
import us.hebi.quickbuf.ProtoMessage;

public class ProtoBufUtils {
    public static > T fromByteBuf(ByteBuf buf, T msg)
            throws InvalidProtocolBufferException {
        final byte[] array;
        final int offset;
        final int length = buf.readableBytes();
        if (buf.hasArray()) {
            array = buf.array();
            offset = buf.arrayOffset() + buf.readerIndex();
        } else {
            array = ByteBufUtil.getBytes(buf, buf.readerIndex(), length, false);
            offset = 0;
        }

        return (T) ProtoMessage.mergeFrom(msg, array, offset, length);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy