//
// $Id$

package com.samskivert.nexus.io;

import com.google.gwt.lang.LongLib;

import com.samskivert.nexus.distrib.NexusService;

/**
 * Handles the encoding of streamable data into a string payload (for delivery to the server).
 */
class ClientOutput extends Streamable.Output
{
    public ClientOutput (GWTIO.Serializer szer, StringBuffer output)
    {
        _szer = szer;
        _output = output;
    }

    @Override public void writeBoolean (boolean value)
    {
        append(value ? "1" : "0");
    }

    @Override public void writeByte (byte value)
    {
        append(String.valueOf(value));
    }

    @Override public void writeShort (short value)
    {
        append(String.valueOf(value));
    }

    @Override public void writeChar (char value)
    {
        // use an int, to avoid having to cope with escaping things
        writeInt((int)value);
    }

    @Override public void writeInt (int value)
    {
        append(String.valueOf(value));
    }

    @Override public void writeLong (long value)
    {
        append(LongLib.toBase64(value));
    }

    @Override public void writeFloat (float value)
    {
        writeDouble(value);
    }

    @Override public void writeDouble (double value)
    {
        append(String.valueOf(value));
    }

    @Override public void writeString (String value)
    {
        if (value == null) {
            writeBoolean(false);
        } else {
            writeBoolean(true);
            writeNonNullString(value);
        }
    }

    @Override public void writeClass (Class<? extends Streamable> clazz)
    {
        writeShort(_szer.getCode(clazz));
    }

    @Override public void writeService (Class<? extends NexusService> clazz)
    {
        writeShort(_szer.getServiceCode(clazz));
    }

    @Override protected <T> Streamer<T> writeStreamer (T value)
    {
        return _szer.<T>writeStreamer(this, value);
    }

    protected void writeNonNullString (String value)
    {
        append(quoteString(value));
    }

    protected String quoteString (String value)
    {
        return value; // TODO
    }

    protected void append (String token)
    {
        _output.append(token);
        _output.append(RPC_SEPARATOR_CHAR);
    }

    protected final GWTIO.Serializer _szer;
    protected final StringBuffer _output;

    protected static final char RPC_SEPARATOR_CHAR = '|';
    protected static final Streamer<Void> NULL_STREAMER = new Streamers.Streamer_Null();
}

@@ -277,16 +277,135 @@
 utput%0A%7B%0A
+    /** The character used to separate values in an encoded payload. */%0A    public static final char SEPARATOR = '%7C';%0A%0A
     publ
@@ -2308,20 +2308,16 @@
 .append(
-RPC_
 SEPARATO
@@ -2317,21 +2317,16 @@
 EPARATOR
-_CHAR
 );%0A    %7D
@@ -2418,66 +2418,8 @@
 t;%0A%0A
-    protected static final char RPC_SEPARATOR_CHAR = '%7C';%0A
     

Make SEPARATOR accessible so that ServerInput can use it.