Add basic netty replication utility
[mdsal.git] / replicate / mdsal-replicate-netty / src / main / java / org / opendaylight / mdsal / replicate / netty / DeltaEncoder.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.replicate.netty;
9
10 import static java.util.Objects.requireNonNull;
11
12 import io.netty.channel.ChannelHandlerContext;
13 import io.netty.handler.codec.MessageToMessageEncoder;
14 import java.io.IOException;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
17
18 final class DeltaEncoder extends MessageToMessageEncoder<AbstractSourceMessage> {
19     private final NormalizedNodeStreamVersion version;
20
21     DeltaEncoder(final NormalizedNodeStreamVersion version) {
22         this.version = requireNonNull(version);
23     }
24
25     @Override
26     protected void encode(final ChannelHandlerContext ctx, final AbstractSourceMessage msg, final List<Object> out)
27             throws IOException {
28         msg.encodeTo(version, out);
29     }
30 }