Class Utf8Marshaller

java.lang.Object
io.github.xezzon.zeroweb.common.grpc.Utf8Marshaller
All Implemented Interfaces:
io.grpc.Metadata.BinaryMarshaller<String>

public class Utf8Marshaller extends Object implements io.grpc.Metadata.BinaryMarshaller<String>
Utf8Marshaller 用于在 gRPC Metadata 中序列化和反序列化 UTF-8 编码的字符串。 它实现了 BinaryMarshaller<String> 接口,提供了将字符串转换为字节数组和将字节数组解析回字符串的方法。
Author:
xezzon
  • Constructor Details

    • Utf8Marshaller

      public Utf8Marshaller()
  • Method Details

    • toBytes

      public byte[] toBytes(String s)
      将字符串序列化为 UTF-8 字节数组。 如果输入字符串为 null,则返回一个空字节数组。
      Specified by:
      toBytes in interface io.grpc.Metadata.BinaryMarshaller<String>
      Parameters:
      s - 要序列化的字符串。
      Returns:
      表示输入字符串的 UTF-8 字节数组。
    • parseBytes

      public String parseBytes(byte[] bytes)
      从 UTF-8 字节数组中反序列化字符串。 如果输入字节数组为 null 或为空,则返回一个空字符串。
      Specified by:
      parseBytes in interface io.grpc.Metadata.BinaryMarshaller<String>
      Parameters:
      bytes - 要反序列化的字节数组。
      Returns:
      从输入字节数组解析的字符串。