Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / ListSerializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies 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
9 package org.opendaylight.openflowjava.protocol.impl.util;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.List;
14
15 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19
20 /**
21  * Serializes list items and their headers
22  * @author michal.polkorab
23  * @param <E> 
24  */
25 public abstract class ListSerializer {
26
27     /**
28      * Serializes item list
29      * @param list list of items to be serialized
30      * @param keyMaker creates key for registry lookup
31      * @param registry stores serializers
32      * @param outBuffer output buffer
33      */
34     public static <E extends DataObject> void serializeList(List<E> list,
35             TypeKeyMaker<E> keyMaker, SerializerRegistry registry, ByteBuf outBuffer) {
36         if (list != null) {
37             for (E item : list) {
38                 OFSerializer<E> serializer = registry.getSerializer(keyMaker.make(item));
39                 serializer.serialize(item, outBuffer);
40             }
41         }
42     }
43
44     /**
45      * Serializes headers of items in list
46      * @param list list of items to be serialized
47      * @param keyMaker creates key for registry lookup
48      * @param registry stores serializers
49      * @param outBuffer output buffer
50      */
51     public static <E extends DataObject> void serializeHeaderList(List<E> list,
52             TypeKeyMaker<E> keyMaker, SerializerRegistry registry, ByteBuf outBuffer) {
53         if (list != null) {
54             for (E item : list) {
55                 HeaderSerializer<E> serializer = registry.getSerializer(keyMaker.make(item));
56                 serializer.serializeHeader(item, outBuffer);
57             }
58         }
59     }
60
61 }