public static StringBuilder toUnderscoreCase(String name)
    {
        StringBuilder buffer = new StringBuilder();
        boolean toLower = false, appendUnderscore = false;
        for (int i = 0, len = name.length(); i < len;)
        {
            char c = name.charAt(i++);
            if (c == '_')
            {
                if (i == len)
                    break;
                if (buffer.length() != 0)
                    appendUnderscore = true;

                continue;
            }

            if (appendUnderscore)
                buffer.append('_');

            if (c > 96 && c < 123)
            {
                buffer.append(c);
                toLower = true;
            }
            else if (c > 64 && c < 91)
            {
                if (toLower)
                {
                    // avoid duplicate underscore
                    if (!appendUnderscore)
                        buffer.append('_');
                    toLower = false;
                }
                buffer.append((char) (c + 32));
            }
            else
            {
                buffer.append(c);
                toLower = false;
            }
            appendUnderscore = false;
        }
        return buffer;
    }
Loads the proto from a {@link Reader}.
protostuff-parser/src/main/java/io/protostuff/parser/ProtoUtil.java