Yes,you're right. I know I have to identify the header and body, that's why I convert messages in $buffer(binary) into @msg.
The question is after I insert 3 bytes into @msg, I don't know how to convert modified message in @msg into the type that can be sent out by syswrite().