event update
package io.nuls.core.event;
import io.nuls.core.chain.entity.NulsData;
-import io.nuls.core.exception.NulsException;
import io.nuls.core.utils.io.ByteBuffer;
import java.io.IOException;
@@ -9,38 +8,49 @@ import java.io.OutputStream;
/**
* Created by Niels on 2017/11/7.
- *
*/
-public class NulsEvent extends NulsData {
-
- public NulsEvent(NulsEventHeader header) {
- this.header = header;
- }
-
+public abstract class NulsEvent extends NulsData {
private NulsEventHeader header;
- public NulsEventHeader getHeader() {
- return header;
- }
+ private NulsData eventBody;
- public void setHeader(NulsEventHeader header) {
+ public NulsEvent(NulsEventHeader header) {
this.header = header;
}
+
@Override
- public int size() {
- return header.size();
+ public final int size() {
+ return header.size() + eventBody.size();
}
@Override
- public void serializeToStream(OutputStream stream) throws IOException {
+ public final void serializeToStream(OutputStream stream) throws IOException {
this.header.serializeToStream(stream);
+ this.eventBody.serializeToStream(stream);
}
@Override
- public void parse(ByteBuffer byteBuffer) {
+ public final void parse(ByteBuffer byteBuffer) {
this.header = new NulsEventHeader();
this.header.parse(byteBuffer);
+ this.eventBody = parseEventBody(byteBuffer);
}
+ protected abstract NulsData parseEventBody(ByteBuffer byteBuffer);
+
+ public NulsData getEventBody() {
+ return eventBody;
+ }
+
+ public void setEventBody(NulsData eventBody) {
+ this.eventBody = eventBody;
+ }
+ public NulsEventHeader getHeader() {
+ return header;
+ }
+
+ public void setHeader(NulsEventHeader header) {
+ this.header = header;
+ }
}
