Class ProtoKit
java.lang.Object
com.iohao.net.common.kit.ProtoKit
JProtobuf serialization utilities for encoding and decoding objects.
- Author:
- 渔民小镇
- date:
- 2022-01-11
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidPre-create and warm up the protobuf codec for the given class on a virtual thread.static <T> TDecode a protobuf byte array into an object of the specified type.static byte[]Encode an object to a protobuf byte array.
-
Method Details
-
encode
Encode an object to a protobuf byte array.- Parameters:
data- the object to encode; ifnull, returns an empty byte array- Returns:
- the encoded bytes, or an empty byte array on failure
-
decode
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; ifnull, returnsnullclazz- the target class- Returns:
- the decoded object, or
nullon failure
-
create
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
-