com.threerings.nexus.net.Streamer_Downstream Maven / Gradle / Ivy
The newest version!
//
// Nexus Core - a framework for developing distributed applications
// http://github.com/threerings/nexus/blob/master/LICENSE
package com.threerings.nexus.net;
import com.threerings.nexus.distrib.Address;
import com.threerings.nexus.distrib.NexusEvent;
import com.threerings.nexus.distrib.NexusObject;
import com.threerings.nexus.io.Streamable;
import com.threerings.nexus.io.Streamer;
/**
* Handles the streaming of {@link Downstream} and/or nested classes.
*/
public class Streamer_Downstream
{
/**
* Handles the streaming of {@link Downstream.Subscribe} instances.
*/
public static class Subscribe implements Streamer {
@Override
public Class> getObjectClass () {
return Downstream.Subscribe.class;
}
@Override
public void writeObject (Streamable.Output out, Downstream.Subscribe obj) {
writeObjectImpl(out, obj);
}
@Override
public Downstream.Subscribe readObject (Streamable.Input in) {
return new Downstream.Subscribe(
in.readValue()
);
}
public static void writeObjectImpl (Streamable.Output out, Downstream.Subscribe obj) {
out.writeValue(obj.object);
}
}
/**
* Handles the streaming of {@link Downstream.SubscribeFailure} instances.
*/
public static class SubscribeFailure implements Streamer {
@Override
public Class> getObjectClass () {
return Downstream.SubscribeFailure.class;
}
@Override
public void writeObject (Streamable.Output out, Downstream.SubscribeFailure obj) {
writeObjectImpl(out, obj);
}
@Override
public Downstream.SubscribeFailure readObject (Streamable.Input in) {
return new Downstream.SubscribeFailure(
in.>readValue(),
in.readString()
);
}
public static void writeObjectImpl (Streamable.Output out, Downstream.SubscribeFailure obj) {
out.writeValue(obj.addr);
out.writeString(obj.cause);
}
}
/**
* Handles the streaming of {@link Downstream.DispatchEvent} instances.
*/
public static class DispatchEvent implements Streamer {
@Override
public Class> getObjectClass () {
return Downstream.DispatchEvent.class;
}
@Override
public void writeObject (Streamable.Output out, Downstream.DispatchEvent obj) {
writeObjectImpl(out, obj);
}
@Override
public Downstream.DispatchEvent readObject (Streamable.Input in) {
return new Downstream.DispatchEvent(
in.readValue()
);
}
public static void writeObjectImpl (Streamable.Output out, Downstream.DispatchEvent obj) {
out.writeValue(obj.event);
}
}
/**
* Handles the streaming of {@link Downstream.ServiceResponse} instances.
*/
public static class ServiceResponse implements Streamer {
@Override
public Class> getObjectClass () {
return Downstream.ServiceResponse.class;
}
@Override
public void writeObject (Streamable.Output out, Downstream.ServiceResponse obj) {
writeObjectImpl(out, obj);
}
@Override
public Downstream.ServiceResponse readObject (Streamable.Input in) {
return new Downstream.ServiceResponse(
in.readInt(),
in.