@Override @VisibleForTesting public void encode(ChannelHandlerContext ctx, NetconfMessage msg, ByteBuf out) throws IOException, TransformerException { Preconditions.checkState(msg instanceof NetconfHelloMessage, "Netconf message of type %s expected, was %s", NetconfHelloMessage.class, msg.getClass()); Optional<NetconfHelloMessageAdditionalHeader> headerOptional = ((NetconfHelloMessage) msg) .getAdditionalHeader(); // If additional header present, serialize it along with netconf hello message if (headerOptional.isPresent()) { out.writeBytes(headerOptional.get().toFormattedString().getBytes(Charsets.UTF_8)); } super.encode(ctx, msg, out); } }