Class ProtoKit

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

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    create(Class<?> clazz)
    Pre-create and warm up the protobuf codec for the given class on a virtual thread.
    <T> T
    decode(byte[] data, Class<T> clazz)
    Decode a protobuf byte array into an object of the specified type.
    byte[]
    encode(Object data)
    Encode an object to a protobuf byte array.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ProtoKit

      public ProtoKit()
  • Method Details

    • encode

      public 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 <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 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