Fixed a bug related to submessage encoding into memory buffer.