getUtf8Codec function

VariableSizeCodec<String, String> getUtf8Codec({
  1. Utf8NullCharacterMode nullCharacterMode = Utf8NullCharacterMode.compatibilityStrip,
})

Returns a codec for encoding and decoding UTF-8 strings.

This codec serializes strings using UTF-8 encoding. The encoded output contains as many bytes as needed to represent the string.

By default, decoded null characters are stripped to preserve @solana/kit compatibility. Prefer Utf8NullCharacterMode.reject for stricter Dart-first decoding when silent data loss would be risky.

Implementation

VariableSizeCodec<String, String> getUtf8Codec({
  Utf8NullCharacterMode nullCharacterMode =
      Utf8NullCharacterMode.compatibilityStrip,
}) {
  return combineCodec(
        getUtf8Encoder(),
        getUtf8Decoder(nullCharacterMode: nullCharacterMode),
      )
      as VariableSizeCodec<String, String>;
}