
io.jsync.eventbus.impl.DoubleMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsync.io Show documentation
Show all versions of jsync.io Show documentation
jsync.io is a non-blocking, event-driven networking framework for Java
/*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/
package io.jsync.eventbus.impl;
import io.jsync.buffer.Buffer;
import io.jsync.eventbus.Message;
/**
* @author Tim Fox
*/
class DoubleMessage extends BaseMessage {
DoubleMessage(boolean send, String address, Double body) {
super(send, address, body);
}
public DoubleMessage(Buffer readBuff) {
super(readBuff);
}
@Override
protected void readBody(int pos, Buffer readBuff) {
boolean isNull = readBuff.getByte(pos) == (byte)0;
if (!isNull) {
body = readBuff.getDouble(++pos);
}
}
@Override
protected void writeBody(Buffer buff) {
if (body == null) {
buff.appendByte((byte)0);
} else {
buff.appendByte((byte)1);
buff.appendDouble(body);
}
}
@Override
protected int getBodyLength() {
return 1 + (body == null ? 0 : 8);
}
@Override
protected Message copy() {
// No need to copy since everything is immutable
return this;
}
@Override
protected byte type() {
return MessageFactory.TYPE_DOUBLE;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy