<div dir="ltr">Thanks for the feedback. Network protocol do encode variable length data with a length prefix, which is the most commonly used mechanism to specify the message boundary so that decoders and encoders would tell which byte belongs to current message, however, the length data usually just means the complete message length, not every string variable within it.<div><br></div><div>For example, in <a href="https://www.postgresql.org/docs/current/protocol-message-formats.html">https://www.postgresql.org/docs/current/protocol-message-formats.html</a>, the postgresql startup message contains a length prefix indicates the total length, while within the message body, multiple string were represented as key-value pair, so we need to call MemorySegment.getString() multiple times to retrieve them, and we must care about the offset value here.</div><div><br></div><div>Thus I think it's quite useful to have a getStringBytes() API in memorySegment, it would be needed and constantly used.</div><div><br></div><div>Best regards.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> 于2024年1月15日周一 22:58写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p><br>
</p>
<div>On 15/01/2024 14:13, Pedro Lamarão
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">Em seg., 15 de jan. de 2024 às 09:57, 刘希晨 <<a href="mailto:benrush0705@gmail.com" target="_blank">benrush0705@gmail.com</a>>
escreveu:<br>
</div>
<div class="gmail_quote">
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div>I think it's a really common behaviour in network
programming, like ByteBuffer, recording the current
message offset as its instance variable, so the caller
could use get() method multiple times
without worrying about its current offset, currently I
wrapped MemorySegment in a ByteBuffer-like structure for
content reading and writing, but with
MemorySegment.getString() and MemorySegment.setString(),
the afterwards offset can't be obtained.</div>
</div>
</blockquote>
</div>
<div><br>
</div>
<div>In my experience, network protocols will encode variable
length data with a length prefix, so that you already know how
many bytes are there before decoding. The alternative, to
encode the variable length data with a sentinel value, is
uncommon.<br>
</div>
</div>
</blockquote>
<p>I was also under this impression - e.g. that network protocols
would probably want to do the encoding/decoding manually, using
more efficient encoding (e.g. variable-length string encoding).</p>
<p>That said, the API you propose, which return just the string
bytes, is not super complex to add in the future, if we still feel
like we need something like that. Let's keep that in our radars.</p>
<p>Maurizio<br>
</p>
<blockquote type="cite">
<div dir="ltr">
<div><br>
</div>
<span class="gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr">
<div>Pedro Lamarão</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote></div>