1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  package org.waarp.openr66.protocol.localhandler.packet;
21  
22  import io.netty.buffer.ByteBuf;
23  import io.netty.buffer.ByteBufAllocator;
24  import io.netty.buffer.Unpooled;
25  import org.waarp.common.utility.WaarpNettyUtil;
26  import org.waarp.openr66.protocol.localhandler.LocalChannelReference;
27  
28  
29  
30  
31  
32  
33  public class StartupPacket extends AbstractLocalPacket {
34    private final Integer localId;
35    private final boolean fromSsl;
36  
37    
38  
39  
40  
41  
42  
43  
44  
45    public static StartupPacket createFromBuffer(final int headerLength,
46                                                 final int middleLength,
47                                                 final int endLength,
48                                                 final ByteBuf buf) {
49      final Integer newId = buf.readInt();
50      final boolean fromSsl = buf.readBoolean();
51      return new StartupPacket(newId, fromSsl);
52    }
53  
54    
55  
56  
57    public StartupPacket(final Integer newId, final boolean fromSsl) {
58      localId = newId;
59      this.fromSsl = fromSsl;
60    }
61  
62    @Override
63    public final boolean hasGlobalBuffer() {
64      return true;
65    }
66  
67    @Override
68    public final synchronized void createAllBuffers(
69        final LocalChannelReference lcr, final int networkHeader) {
70      final int headerSize = 4;
71      final int middleSize = 1;
72      final int endSize = 0;
73      final int globalSize =
74          networkHeader + LOCAL_HEADER_SIZE + headerSize + middleSize + endSize;
75      int offset = networkHeader + LOCAL_HEADER_SIZE;
76      global = ByteBufAllocator.DEFAULT.ioBuffer(globalSize, globalSize);
77      header = WaarpNettyUtil.slice(global, offset, headerSize);
78      header.writeInt(localId);
79      offset += headerSize;
80      middle = WaarpNettyUtil.slice(global, offset, middleSize);
81      middle.writeBoolean(fromSsl);
82      end = Unpooled.EMPTY_BUFFER;
83    }
84  
85    @Override
86    public final String toString() {
87      return "StartupPacket: " + localId;
88    }
89  
90    @Override
91    public final byte getType() {
92      return LocalPacketFactory.STARTUPPACKET;
93    }
94  
95    
96  
97  
98    public final Integer getLocalId() {
99      return localId;
100   }
101 
102   public final boolean isFromSsl() {
103     return fromSsl;
104   }
105 
106 }