public void decodeBytesUsingCharset(ByteBuffer bb, RENDER_ENUM renderSetting,
			boolean trimTrailingNulls) {
		if (!bb.hasRemaining()) {
			// early exit avoids problems trying to flush un-initialized codec later
			return;
		}
		CharsetDecoder codec = cs.newDecoder()
				.onMalformedInput(CodingErrorAction.REPORT)
				.onUnmappableCharacter(CodingErrorAction.REPORT);
		CharBuffer cb = CharBuffer.allocate(Math.max(10, bb.remaining() + (bb.remaining() / 2)));
		while (bb.hasRemaining()) {
			CoderResult cr = codec.decode(bb, cb, true);
			if (!bb.hasRemaining() && trimTrailingNulls) {
				// if this is the last chunk of text, trim nulls if necessary
				// TODO: this conditional is a bit fragile and could fail to trigger if a long
				// run of trailing nulls was split over multiple charbuffers.  This shouldn't
				// happen because of the allocated size of the charbuffer is tied to the size of the
				// input bytebuffer
				trimTrailingNulls(cb);
			}
			flushStringModeCharBuf(cb, renderSetting);
			if ( cr.isError() ) {
				addByteSeq(bb, cr.length());
			}
			else if (cr.isUnderflow()) {
				// there was a trailing byte sequence that the charset needs more bytes to
				// finish. Since we gave the charset all the bytes, any remaining will have to
				// be rendered as bytes values.
				// This can also trigger for successful end-of-input, remaining == 0
				addByteSeq(bb, bb.remaining());
			}
		}

		CoderResult flushResult = codec.flush(cb);
		if (!flushResult.isUnderflow()) {
			// error, should not happen
		}
		flushStringModeCharBuf(cb, renderSetting);
	}
Adds the characters found in the supplied {@link ByteBuffer} to the result.
<p>
Any portions of the byte buffer that cause problems for the charset codec will be added
as a {@link #addByteSeq(ByteBuffer, int) byte sequence}.
<p>
Characters that are outside the traditional ASCII range will be rendered as-is or as
escape sequences, depending on the RENDER_ENUM setting.
 
@param bb {@link ByteBuffer} containing bytes of a string
@param renderSetting {@link RENDER_ENUM}
@param trimTrailingNulls boolean flag, if true trailing null bytes will not be included
in the rendered output
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/StringRenderBuilder.java