Example usage for io.netty.buffer ByteBufUtil utf8MaxBytes

List of usage examples for io.netty.buffer ByteBufUtil utf8MaxBytes

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufUtil utf8MaxBytes.

Prototype

public static int utf8MaxBytes(CharSequence seq) 

Source Link

Document

Returns max bytes length of UTF8 character sequence.

Usage

From source file:io.atomix.cluster.messaging.impl.MessageEncoder.java

License:Apache License

private void encodeRequest(InternalRequest request, ByteBuf out) {
    encodeMessage(request, out);// w  ww . j  a va2  s. c o m

    final ByteBuf buf = out.alloc().buffer(ByteBufUtil.utf8MaxBytes(request.subject()));
    try {
        final int length = ByteBufUtil.writeUtf8(buf, request.subject());
        // write length of message type
        out.writeShort(length);
        // write message type bytes
        out.writeBytes(buf);
    } finally {
        buf.release();
    }
}