private static ByteBuf encode ( MessageType messageType , Consumer < ByteBuf > messageEncoder , ByteBuf buffer ) throws UaException { buffer . writeMedium ( MessageType . toMediumInt ( messageType ) ) ; buffer . writeByte ( ' ' ) ; int lengthIndex = buffer . writerIndex ( ) ; buffer . writeInt ( 0 ) ; int indexBefore = buffer . writerIndex ( ) ; messageEncoder . accept ( buffer ) ; int indexAfter = buffer . writerIndex ( ) ; int bytesWritten = indexAfter - indexBefore ; buffer . writerIndex ( lengthIndex ) ; buffer . writeInt ( 8 + bytesWritten ) ; buffer . writerIndex ( indexAfter ) ; return buffer ; }
Encode a simple UA TCP message .