public class RpcDataPackage extends Object implements Readable, Writerable
-----------------------------------
| Head | Meta | Data | Attachment |
-----------------------------------
1. with fixed 12 byte length as follow format
----------------------------------------------
| PRPC | TotalSize(int32) | MetaSize(int32) |
----------------------------------------------
TotalSize = totalSize
MetaSize = Meta object size
2. body proto description as follow
message RpcMeta {
RpcRequestMeta request = 1;
RpcResponseMeta response = 2;
int32 compress_type = 3; // 0:nocompress 1:Snappy 2:gzip
int64 correlation_id = 4;
int32 attachment_size = 5;
ChunkInfo chuck_info = 6;
bytes authentication_data = 7;
};
message Request {
required string service_name = 1;
required string method_name = 2;
int64 log_id = 3;
int64 traceId = 4;
int64 spanId = 5;
int64 parentSpanId = 6;
repeated RpcRequestMetaExtField rpcRequestMetaExt = 7;
bytes extraParam = 110;
};
message Response {
int32 error_code = 1;
string error_text = 2;
};
message ChunkInfo {
required int64 stream_id = 1;
required int64 chunk_id = 2;
};
message RpcRequestMetaExtField {
string key = 1;
string value = 2;
};
3. customize transport data message.
4. attachment body data message
| 构造器和说明 |
|---|
RpcDataPackage() |
| 限定符和类型 | 方法和说明 |
|---|---|
RpcDataPackage |
attachment(byte[] attachment)
Attachment.
|
RpcDataPackage |
authenticationData(byte[] authenticationData)
Authentication data.
|
static RpcDataPackage |
buildRpcDataPackage(RpcMethodInfo methodInfo,
Object[] args)
Builds the rpc data package.
|
List<RpcDataPackage> |
chunk(long chunkSize)
To split current
RpcDataPackage by chunkSize. if chunkSize great than data length will not do split. |
RpcDataPackage |
chunkInfo(long streamId,
int chunkId)
Chunk info.
|
RpcDataPackage |
compressType(int compressType)
Compress type.
|
RpcDataPackage |
copy()
Copy.
|
RpcDataPackage |
correlationId(long correlationId)
Correlation id.
|
RpcDataPackage |
data(byte[] data)
Data.
|
RpcDataPackage |
errorCode(int errorCode)
Error code.
|
RpcDataPackage |
errorText(String errorText)
Error text.
|
RpcDataPackage |
extraParams(byte[] params)
Extra params.
|
byte[] |
getAttachment()
Gets the attachment.
|
Long |
getChunkStreamId()
Gets the chunk stream id.
|
byte[] |
getData()
Gets the data.
|
RpcDataPackage |
getErrorResponseRpcDataPackage(int errorCode,
String errorText)
Gets the error response rpc data package.
|
RpcDataPackage |
getErrorResponseRpcDataPackage(RpcResponseMeta responseMeta)
Gets the error response rpc data package.
|
RpcHeadMeta |
getHead()
Gets the head.
|
RpcMeta |
getRpcMeta()
Gets the rpc meta.
|
long |
getTimeStamp()
Gets the time stamp.
|
boolean |
isChunkPackage()
Checks if is chunk package.
|
boolean |
isFinalPackage()
Checks if is final package.
|
RpcDataPackage |
logId(long logId)
Log id.
|
RpcDataPackage |
magicCode(String magicCode)
set magic code.
|
void |
mergeData(byte[] data)
Merge data.
|
String |
methodName()
Method name.
|
RpcDataPackage |
methodName(String methodName)
Method name.
|
void |
read(byte[] bytes)
Do deserializable action.
|
String |
serviceName()
Service name.
|
RpcDataPackage |
serviceName(String serviceName)
Service name.
|
void |
setAttachment(byte[] attachment)
Sets the attachment.
|
void |
setData(byte[] data)
Sets the data.
|
void |
setHead(RpcHeadMeta head)
Sets the head.
|
void |
setMagicCode(String magicCode)
Sets the magic code.
|
protected void |
setRpcMeta(RpcMeta rpcMeta)
Sets the rpc meta.
|
void |
setTimeStamp(long timeStamp)
Sets the time stamp.
|
Trace |
trace()
Trace.
|
RpcDataPackage |
trace(Trace trace)
set Trace value.
|
byte[] |
write()
Write.
|
public void mergeData(byte[] data)
data - the datapublic boolean isChunkPackage()
public boolean isFinalPackage()
public Long getChunkStreamId()
public List<RpcDataPackage> chunk(long chunkSize)
RpcDataPackage by chunkSize. if chunkSize great than data length will not do split.List return will never be null or empty.chunkSize - target size to splitList of RpcDataPackage after splitpublic RpcDataPackage copy()
public RpcDataPackage magicCode(String magicCode)
magicCode - the magic codepublic RpcDataPackage serviceName(String serviceName)
serviceName - the service namepublic String serviceName()
public String methodName()
public RpcDataPackage methodName(String methodName)
methodName - the method namepublic RpcDataPackage data(byte[] data)
data - the datapublic RpcDataPackage attachment(byte[] attachment)
attachment - the attachmentpublic RpcDataPackage authenticationData(byte[] authenticationData)
authenticationData - the authentication datapublic RpcDataPackage correlationId(long correlationId)
correlationId - the correlation idpublic RpcDataPackage compressType(int compressType)
compressType - the compress typepublic RpcDataPackage logId(long logId)
logId - the log idpublic RpcDataPackage errorCode(int errorCode)
errorCode - the error codepublic RpcDataPackage errorText(String errorText)
errorText - the error textpublic RpcDataPackage extraParams(byte[] params)
params - the paramspublic RpcDataPackage chunkInfo(long streamId, int chunkId)
streamId - the stream idchunkId - the chunk idpublic RpcDataPackage trace(Trace trace)
trace - the tracepublic Trace trace()
public void setMagicCode(String magicCode)
magicCode - the new magic codepublic RpcHeadMeta getHead()
public void setHead(RpcHeadMeta head)
head - the new headpublic RpcMeta getRpcMeta()
protected void setRpcMeta(RpcMeta rpcMeta)
rpcMeta - the new rpc metapublic byte[] getData()
public void setData(byte[] data)
data - the new datapublic long getTimeStamp()
public void setTimeStamp(long timeStamp)
timeStamp - the new time stamppublic byte[] getAttachment()
public void setAttachment(byte[] attachment)
attachment - the new attachmentpublic RpcDataPackage getErrorResponseRpcDataPackage(int errorCode, String errorText)
errorCode - the error codeerrorText - the error textpublic RpcDataPackage getErrorResponseRpcDataPackage(RpcResponseMeta responseMeta)
responseMeta - the response metapublic byte[] write()
Writerablewrite 在接口中 Writerablepublic void read(byte[] bytes)
Readablepublic static RpcDataPackage buildRpcDataPackage(RpcMethodInfo methodInfo, Object[] args) throws IOException
methodInfo - the method infoargs - the argsIOException - Signals that an I/O exception has occurred.Copyright © 2022 Baidu, Inc.. All rights reserved.