<div dir="ltr"><div dir="ltr">On Tue, Nov 11, 2025 at 3:10 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Going back to this... do you have a use case where you would like to <br>
know the byte length of a string encoded in a given charset?<br></blockquote><div><br></div>The main use-case is to know if a preexisting buffer is big enough to write out an encoded string to.</div><div class="gmail_quote gmail_quote_container"><br></div><div class="gmail_quote gmail_quote_container">As well, for the protobuf example, it's writing a varint length as a prefix before the string data, so it needs to know what the encoded length is to know how many bytes to reserve to encode the length itself.</div><div class="gmail_quote gmail_quote_container"><br></div><div class="gmail_quote gmail_quote_container">(I'm happy to separate out the discussion of string.getBytesLength(Charset), or not, if you think it could safely be pursued separately without risk of dead ends. I mentioned it here because the use-case is at least somewhat related, and in case you saw connections I'd missed.)</div></div>