UartBus source documentation
UartbusPacketDispatch.java
1 package eu.javaexperience.electronic.uartbus.rpc.service;
2 
3 import java.util.Arrays;
4 
7 import eu.javaexperience.reflect.Mirror;
8 
10 {
11  protected ParsedUartBusPacket packet;
12  protected int ep = 0;
13 
15  {
16  this.packet = packet;
17  }
18 
19  public ParsedUartBusPacket getPacket()
20  {
21  return packet;
22  }
23 
24  public byte[] getPayload()
25  {
26  return packet.payload;
27  }
28 
29  public int getDispatchByteIndex()
30  {
31  return ep;
32  }
33 
34  public void setDispatchByteIndex(int index)
35  {
36  ep = index;
37  }
38 
39  public int getRemainingBytes()
40  {
41  return getPayload().length-ep;
42  }
43 
44  public byte popNextByte()
45  {
46  return packet.payload[ep++];
47  }
48 
49  public byte[] getCurrentPath()
50  {
51  return Arrays.copyOfRange(packet.payload, 0, Math.max(0, ep-1));
52  }
53 
54  public byte[] getPayloadTo(int dix)
55  {
56  return Arrays.copyOfRange(packet.payload, 0, Math.max(0, dix-1));
57  }
58 
59  public PacketReader createReaderCurrentPoz()
60  {
61  if(ep == packet.payload.length)
62  {
63  return new PacketReader(Mirror.emptyByteArray);
64  }
65  return new PacketReader(Arrays.copyOfRange(packet.payload, ep, packet.payload.length));
66  }
67 
68  public void moveDispatch(int diff)
69  {
70  ep += diff;
71  }
72 }