मैं एक एन्कोडर लिख रहा हूं जो एक JSON- संदेश को एनयूएल-टर्मिनेट करता है ताकि संदेश खंडित होने पर इसे डीकोड किया जा सके।मुझे Nette4 Encoder में ByteBuf.retain() का उपयोग कब करना है?
मुझे यह नमूना मिला ->click जहां ByteBuf.retain()
को आउटपुट में मौजूदा बाइटबफ लिखने के अंत में बुलाया गया था। उन्होंने ऐसा क्यों किया, और इसकी आवश्यकता क्यों है?
public class FrameEncoder extends MessageToMessageEncoder<ByteBuf> {
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
out.add(msg.retain());
out.add(ctx.alloc().buffer(1).writeByte(NUL));
}
}