All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threerings.nexus.distrib.Streamer_Address 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.distrib;

import com.threerings.nexus.io.Streamable;
import com.threerings.nexus.io.Streamer;

/**
 * Handles the streaming of {@link Address} and/or nested classes.
 */
public class Streamer_Address
{
    /**
     * Handles the streaming of {@link Address.OfKeyed} instances.
     */
    public static class OfKeyed
        implements Streamer>
    {
        @Override
        public Class getObjectClass () {
            return Address.OfKeyed.class;
        }

        @Override
        public void writeObject (Streamable.Output out, Address.OfKeyed obj) {
            writeObjectImpl(out, obj);
        }

        @Override
        public Address.OfKeyed readObject (Streamable.Input in) {
            return new Address.OfKeyed(
                in.readString(),
                in.readClass(),
                in.>readValue()
            );
        }

        public static  void writeObjectImpl (Streamable.Output out, Address.OfKeyed obj) {
            Streamer_Address.OfTyped.writeObjectImpl(out, obj);
            out.writeValue(obj.key);
        }
    }

    /**
     * Handles the streaming of {@link Address.OfSingleton} instances.
     */
    public static class OfSingleton
        implements Streamer>
    {
        @Override
        public Class getObjectClass () {
            return Address.OfSingleton.class;
        }

        @Override
        public void writeObject (Streamable.Output out, Address.OfSingleton obj) {
            writeObjectImpl(out, obj);
        }

        @Override
        public Address.OfSingleton readObject (Streamable.Input in) {
            return new Address.OfSingleton(
                in.readString(),
                in.readClass()
            );
        }

        public static  void writeObjectImpl (Streamable.Output out, Address.OfSingleton obj) {
            Streamer_Address.OfTyped.writeObjectImpl(out, obj);
        }
    }

    /**
     * Handles the streaming of {@link Address.OfAnonymous} instances.
     */
    public static class OfAnonymous
        implements Streamer
    {
        @Override
        public Class getObjectClass () {
            return Address.OfAnonymous.class;
        }

        @Override
        public void writeObject (Streamable.Output out, Address.OfAnonymous obj) {
            writeObjectImpl(out, obj);
        }

        @Override
        public Address.OfAnonymous readObject (Streamable.Input in) {
            return new Address.OfAnonymous(
                in.readString(),
                in.readInt()
            );
        }

        public static  void writeObjectImpl (Streamable.Output out, Address.OfAnonymous obj) {
            Streamer_Address.writeObjectImpl(out, obj);
            out.writeInt(obj.id);
        }
    }

    /**
     * Handles the streaming of {@link Address.OfTyped} instances.
     */
    public static class OfTyped
        implements Streamer>
    {
        @Override
        public Class getObjectClass () {
            return Address.OfTyped.class;
        }

        @Override
        public void writeObject (Streamable.Output out, Address.OfTyped obj) {
            writeObjectImpl(out, obj);
        }

        @Override
        public Address.OfTyped readObject (Streamable.Input in) {
            return new Address.OfTyped(
                in.readString(),
                in.readClass()
            );
        }

        public static  void writeObjectImpl (Streamable.Output out, Address.OfTyped obj) {
            Streamer_Address.writeObjectImpl(out, obj);
            out.writeClass(obj.clazz);
        }
    }

    public static  void writeObjectImpl (Streamable.Output out, Address obj) {
        out.writeString(obj.host);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy