Class ProtoKit

java.lang.Object
com.iohao.net.common.kit.ProtoKit

public final class ProtoKit extends Object
JProtobuf serialization utilities for encoding and decoding objects.
Author:
渔民小镇
date:
2022-01-11
  • Method Details

    • encode

      public static byte[] encode(Object data)
      Encode an object to a protobuf byte array.
      Parameters:
      data - the object to encode; if null, returns an empty byte array
      Returns:
      the encoded bytes, or an empty byte array on failure
    • decode

      public static <T> T decode(byte[] data, Class<T> clazz)
      Decode a protobuf byte array into an object of the specified type.
      Type Parameters:
      T - the target type
      Parameters:
      data - the byte array to decode; if null, returns null
      clazz - the target class
      Returns:
      the decoded object, or null on failure
    • create

      public static void create(Class<?> clazz)
      Pre-create and warm up the protobuf codec for the given class on a virtual thread.
      Parameters:
      clazz - the class to pre-create a codec for