more code
[iotcloud.git] / src / java / iotcloud / Entry.java
1 package iotcloud;
2 import java.nio.ByteBuffer;
3
4 abstract class Entry {
5         static final byte TypeKeyValue = 1;
6         static final byte TypeLastMessage = 2;
7         static final byte TypeRejectedMessage = 3;
8         static final byte TypeTableStatus = 4;
9
10         static Entry decode(ByteBuffer bb) {
11                 byte type=bb.get();
12                 switch(type) {
13                 case TypeKeyValue:
14                         return KeyValue.decode(bb);
15                 case TypeLastMessage:
16                         return LastMessage.decode(bb);
17                 case TypeRejectedMessage:
18                         return RejectedMessage.decode(bb);
19                 case TypeTableStatus:
20                         return TableStatus.decode(bb);
21                 default:
22                         throw new Error("Unrecognized Entry Type: "+type);
23                 }
24         }
25
26         abstract void encode(ByteBuffer bb);
27
28         abstract int getSize();
29 }