Class ProtoKit
java.lang.Object
com.iohao.net.common.kit.ProtoKit
JProtobuf serialization utilities for encoding and decoding objects.
- Author:
- 渔民小镇
- date:
- 2022-01-11
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPre-create and warm up the protobuf codec for the given class on a virtual thread.<T> TDecode a protobuf byte array into an object of the specified type.byte[]Encode an object to a protobuf byte array.
-
Constructor Details
-
ProtoKit
public ProtoKit()
-
-
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
-