static int rightTrimIndex(final byte[] string, final int offset, final int length) {
        if (string == null) {
            return -1;
        }
        checkBounds(string, offset, length);

        int index = offset + length - 1;
        while (index >= offset && string[index] <= ' ') {
            index--;
        }
        return index + 1;
    }
copy google protocol buffer
https://github.com/google/protobuf/blob/master/java/src/main/java/com/google/protobuf/CodedOutputStream.java
commons/src/main/java/com/navercorp/pinpoint/common/util/BytesUtils.java