pandaapo commented on PR #4702:
URL: https://github.com/apache/eventmesh/pull/4702#issuecomment-1879463596

   > I think LengthFieldBasedFrameDecoder can not solve this problem. length = 
CONSTANT_MAGIC_FLAG.length + VERSION.length + headerLength + bodyLength; 
![image](https://private-user-images.githubusercontent.com/15797831/294534301-520a9080-bcf5-49ce-84e1-bb56192c453e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDQ1MDA5MzMsIm5iZiI6MTcwNDUwMDYzMywicGF0aCI6Ii8xNTc5NzgzMS8yOTQ1MzQzMDEtNTIwYTkwODAtYmNmNS00OWNlLTg0ZTEtYmI1NjE5MmM0NTNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAxMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMTA2VDAwMjM1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNhMzRjMzk4MTc4MTA1NDZkNzM5Njg5ZWRlYmNiZDI5ODQ1NzZjZTY5NDdiMzk5MTZiY2Y0MzVjNTg5N2QwZDkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.WxufbuIWYvRnVe-xydH_doWDC3pcAfi2WZZmkPNsD9s)
 The actual size o
 f the entire package is four bytes larger than the length. It does not conform 
to the decoding scenario of the LengthFieldBasedFrameDecoder.
   
   @mxsm 
   
   It seems not to be the case. For example, one of the constructors is 
   ```
   LengthFieldBasedFrameDecoder(
     int maxFrameLength,
     int lengthFieldOffset,
     int lengthFieldLength,
     int lengthAdjustment,
     int initialBytesToStrip)
   ```
   . 
   If you define it like this: 
   ```
   new LengthFieldBasedFrameDecoder(
     /* maximum packet length */
     max frame length, 
     /* the offset of "package length" field, i,e CONSTANT_MAGIC_FLAG.length + 
VERSION.length */
     13,
     /** 
      * the length of "package length" field, which should be 4
      */
     4,
     /** 
      * adjustment to the length field value, i.e. subtracting "package length" 
field value by "CONSTANT_MAGIC_FLAG.length  + 
      * VERSION.length - 'Header length' field's length".  Ultimately, this 
gives the length of the 'Header length' field,
      *  the 'Header' field, and the 'body' field
      */
     -9,
     /* strip off the first 4 bytes of the decoded frame, i.e. the length of 
"Header length" field */
     4)
   ```
   , the resulting decoded `ByteBuf` should be the concatenation of Header and 
body.
   
   ---
   好像并非如此。比如构造函数之一是
   ```
   LengthFieldBasedFrameDecoder(
     int maxFrameLength,
     int lengthFieldOffset,
     int lengthFieldLength,
     int lengthAdjustment,
     int initialBytesToStrip)
   ```
   ,如果您这样定义
   ```
   new LengthFieldBasedFrameDecoder(
     /* 数据包长度上限 */
     max frame length,
     /* 长度字段即“package length”的偏移量:CONSTANT_MAGIC_FLAG.length + VERSION.length */
     13,
     /**
      * 长度字段即“package length”的长度:"package length" field's length
      */
     4, 
     /**
      * 对长度字段值的补长,即将长度字段值减去“CONSTANT_MAGIC_FLAG.length + VERSION.length - 
'Header length' field's 
      * length”,最终得到的是“Header length”字段、“Header”字段和“body”字段的长度
      */
     -9, 
     /* 剥离掉解码帧的最前面4个字节,即“Header length”字段长度 */
     4)
   ```
   ,最终的解码出来的ByteBuf应该就是Header + body。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to