com.dyuproject.protostuff
Class JsonOutput

java.lang.Object
  extended by com.dyuproject.protostuff.JsonOutput
All Implemented Interfaces:
Output, StatefulOutput

public final class JsonOutput
extends java.lang.Object
implements Output, StatefulOutput

An output used for writing data with json format.

Author:
David Yu
Date created:
Nov 20, 2009

Constructor Summary
JsonOutput(org.codehaus.jackson.JsonGenerator generator)
           
JsonOutput(org.codehaus.jackson.JsonGenerator generator, boolean numeric)
           
JsonOutput(org.codehaus.jackson.JsonGenerator generator, boolean numeric, Schema<?> schema)
           
 
Method Summary
 int getLastNumber()
          Gets the last field number written.
 boolean isLastRepeated()
          Returns true if the last written field was a repeated field.
 boolean isNumeric()
          Returns whether the incoming messages' field names are numeric.
 JsonOutput reset()
          Resets this output for re-use.
 void updateLast(Schema<?> schema, Schema<?> lastSchema)
           
 JsonOutput use(Schema<?> schema)
          Before serializing a message/object tied to a schema, this should be called.
 void writeBool(int fieldNumber, boolean value, boolean repeated)
           
 void writeByteArray(int fieldNumber, byte[] value, boolean repeated)
           
 void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated)
           
 void writeBytes(int fieldNumber, ByteString value, boolean repeated)
           
 void writeDouble(int fieldNumber, double value, boolean repeated)
           
 void writeEnum(int fieldNumber, int value, boolean repeated)
           
 void writeFixed32(int fieldNumber, int value, boolean repeated)
           
 void writeFixed64(int fieldNumber, long value, boolean repeated)
           
 void writeFloat(int fieldNumber, float value, boolean repeated)
           
 void writeInt32(int fieldNumber, int value, boolean repeated)
           
 void writeInt64(int fieldNumber, long value, boolean repeated)
           
<T> void
writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated)
           
 void writeSFixed32(int fieldNumber, int value, boolean repeated)
           
 void writeSFixed64(int fieldNumber, long value, boolean repeated)
           
 void writeSInt32(int fieldNumber, int value, boolean repeated)
           
 void writeSInt64(int fieldNumber, long value, boolean repeated)
           
 void writeString(int fieldNumber, java.lang.String value, boolean repeated)
           
 void writeUInt32(int fieldNumber, int value, boolean repeated)
           
 void writeUInt64(int fieldNumber, long value, boolean repeated)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonOutput

public JsonOutput(org.codehaus.jackson.JsonGenerator generator)

JsonOutput

public JsonOutput(org.codehaus.jackson.JsonGenerator generator,
                  boolean numeric)

JsonOutput

public JsonOutput(org.codehaus.jackson.JsonGenerator generator,
                  boolean numeric,
                  Schema<?> schema)
Method Detail

reset

public JsonOutput reset()
Resets this output for re-use.


use

public JsonOutput use(Schema<?> schema)
Before serializing a message/object tied to a schema, this should be called. This also resets the internal state of this output.


isNumeric

public boolean isNumeric()
Returns whether the incoming messages' field names are numeric.


getLastNumber

public int getLastNumber()
Gets the last field number written.


isLastRepeated

public boolean isLastRepeated()
Returns true if the last written field was a repeated field.


updateLast

public void updateLast(Schema<?> schema,
                       Schema<?> lastSchema)
Specified by:
updateLast in interface StatefulOutput

writeBool

public void writeBool(int fieldNumber,
                      boolean value,
                      boolean repeated)
               throws java.io.IOException
Specified by:
writeBool in interface Output
Throws:
java.io.IOException

writeByteArray

public void writeByteArray(int fieldNumber,
                           byte[] value,
                           boolean repeated)
                    throws java.io.IOException
Specified by:
writeByteArray in interface Output
Throws:
java.io.IOException

writeByteRange

public void writeByteRange(boolean utf8String,
                           int fieldNumber,
                           byte[] value,
                           int offset,
                           int length,
                           boolean repeated)
                    throws java.io.IOException
Specified by:
writeByteRange in interface Output
Throws:
java.io.IOException

writeBytes

public void writeBytes(int fieldNumber,
                       ByteString value,
                       boolean repeated)
                throws java.io.IOException
Specified by:
writeBytes in interface Output
Throws:
java.io.IOException

writeDouble

public void writeDouble(int fieldNumber,
                        double value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeDouble in interface Output
Throws:
java.io.IOException

writeEnum

public void writeEnum(int fieldNumber,
                      int value,
                      boolean repeated)
               throws java.io.IOException
Specified by:
writeEnum in interface Output
Throws:
java.io.IOException

writeFixed32

public void writeFixed32(int fieldNumber,
                         int value,
                         boolean repeated)
                  throws java.io.IOException
Specified by:
writeFixed32 in interface Output
Throws:
java.io.IOException

writeFixed64

public void writeFixed64(int fieldNumber,
                         long value,
                         boolean repeated)
                  throws java.io.IOException
Specified by:
writeFixed64 in interface Output
Throws:
java.io.IOException

writeFloat

public void writeFloat(int fieldNumber,
                       float value,
                       boolean repeated)
                throws java.io.IOException
Specified by:
writeFloat in interface Output
Throws:
java.io.IOException

writeInt32

public void writeInt32(int fieldNumber,
                       int value,
                       boolean repeated)
                throws java.io.IOException
Specified by:
writeInt32 in interface Output
Throws:
java.io.IOException

writeInt64

public void writeInt64(int fieldNumber,
                       long value,
                       boolean repeated)
                throws java.io.IOException
Specified by:
writeInt64 in interface Output
Throws:
java.io.IOException

writeSFixed32

public void writeSFixed32(int fieldNumber,
                          int value,
                          boolean repeated)
                   throws java.io.IOException
Specified by:
writeSFixed32 in interface Output
Throws:
java.io.IOException

writeSFixed64

public void writeSFixed64(int fieldNumber,
                          long value,
                          boolean repeated)
                   throws java.io.IOException
Specified by:
writeSFixed64 in interface Output
Throws:
java.io.IOException

writeSInt32

public void writeSInt32(int fieldNumber,
                        int value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeSInt32 in interface Output
Throws:
java.io.IOException

writeSInt64

public void writeSInt64(int fieldNumber,
                        long value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeSInt64 in interface Output
Throws:
java.io.IOException

writeString

public void writeString(int fieldNumber,
                        java.lang.String value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeString in interface Output
Throws:
java.io.IOException

writeUInt32

public void writeUInt32(int fieldNumber,
                        int value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeUInt32 in interface Output
Throws:
java.io.IOException

writeUInt64

public void writeUInt64(int fieldNumber,
                        long value,
                        boolean repeated)
                 throws java.io.IOException
Specified by:
writeUInt64 in interface Output
Throws:
java.io.IOException

writeObject

public <T> void writeObject(int fieldNumber,
                            T value,
                            Schema<T> schema,
                            boolean repeated)
                 throws java.io.IOException
Specified by:
writeObject in interface Output
Throws:
java.io.IOException


Copyright © 2009-2012. All Rights Reserved.