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

com.dyuproject.protostuff.compiler.java_bean.stg Maven / Gradle / Ivy

group java_bean : base;

map_value_prefix ::= [
    "Int64":  "new Long(",
    "UInt64":  "new Long(",
    "SInt64":  "new Long(",
    "Fixed64":  "new Long(",
    "SFixed64":  "new Long(",
    "Float": "new Float(",
    "Double": "new Double(",
    "Bool": "new Boolean(",
    "Bytes": "ByteString.bytesDefaultValue(\"",
    "String": "ByteString.stringDefaultValue(\"",
    "EnumField": ,
    default: "new Integer("
]

map_value_suffix ::= [
    "Int64": "l)",
    "UInt64": "l)",
    "SInt64": "l)",
    "Fixed64": "l)",
    "SFixed64": "l)",
    "Float": "f)",
    "Double": "d)",
    "Bytes": "\")",
    "String": "\")",
    "EnumField": ,
    default: ")"
]

map_primitive_wrapper ::= [
    "int": "Integer",
    "long": "Long",
    "float": "Float",
    "double": "Double",
    "boolean": "Boolean",
    default: key
]

map_primitive_number_suffix ::= [
    "Int64": "l",
    "UInt64": "l",
    "SInt64": "l",
    "Fixed64": "l",
    "SFixed64": "l",
    "Float": "f",
    "Double": "d",
    default: 
]

//#enum begin

enum_block(eg, module, options, nested) ::= <<




public enum  implements com.dyuproject.protostuff.EnumLite\<\>
{
    ()}; separator=",\n">;
    
    public final int number;
    
    private  (int number)
    {
        this.number = number;
    }
    
    public int getNumber()
    {
        return number;
    }
    
    public static  valueOf(int number)
    {
        switch(number) 
        {
            
            default: return null;
        }
    }
}

>>

enum_header(eg, module, options) ::= <<


package ;

>>

enum_switch_case(value, options) ::= <<
case : return ;
>>

//#message begin

message_block(message, module, options, nested) ::= <<




public static final class  
{
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}

>>

message_header(message, module, options) ::= <<


package ;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import java.util.ArrayList;
import java.util.List;




import com.dyuproject.protostuff.ByteString;


import com.dyuproject.protostuff.ByteString;



import com.dyuproject.protostuff.GraphIOUtil;
import com.dyuproject.protostuff.Input;
import com.dyuproject.protostuff.Message;
import com.dyuproject.protostuff.Output;

import com.dyuproject.protostuff.Pipe;


import com.dyuproject.protostuff.Schema;

import com.dyuproject.protostuff.UninitializedMessageException;



>>

message_impl_declaration(message, options) ::= <<

, 

implements 

Externalizable, Message\<\>, Schema\<\>
>>

message_default_instance(message, options) ::= <<

public static Schema\<\> getSchema()
{
    return DEFAULT_INSTANCE;
}

public static  getDefaultInstance()
{
    return DEFAULT_INSTANCE;
}

static final  DEFAULT_INSTANCE = new ();

>>

field_defaults_declaration(field, options) ::= <<




static final  DEFAULT_ = ;

static final  DEFAULT_ = ;


static final  DEFAULT_ = ;



>>

field_default_value(field, options) ::= <<













>>

field_declaration(field, options, modifier) ::= <<

List\<\> ;

 ;

>>

field_singular_type(field, options) ::= <<













>>

field_assign_defaults(field, options) ::= <<


 = DEFAULT_


>>

message_constructor(message, options) ::= <<

public ()
{
    
}


public (
    
)
{
    
}



>>

field_declare_constructor_singular(field, options) ::= <<

 

>>

field_assign_constructor_singular(field, options) ::= <<

this. = ;

>>

message_getters_and_setters(message, options) ::= <<
// getters and setters

>>

field_getters_and_setters(field, options, message) ::= <<

// 


public List\<\> getList()
{
    return ;
}

public  setList(List\<\> )
{
    this. = ;
    
}


public  get(int index)
{
    return  == null ? null : .get(index);
}

public int getCount()
{
    return  == null ? 0 : .size();
}

public  add( )
{
    if(this. == null)
        this. = new ArrayList\<\>();
    this..add();
    
}





public  get()
{
    
    
    return ;
    
    return  == null ?  : ;
    
    
    return ;
    
}

public  set( )
{
    this. = ;
    
}


>>

builder_pattern_return_type(field, options, type) ::= <<



void

>>

builder_pattern_return(field, options) ::= <<

return this;

>>

message_impl_serializable(message, options) ::= <<
// java serialization

public void readExternal(ObjectInput in) throws IOException
{
    GraphIOUtil.mergeDelimitedFrom(in, this, this);
}

public void writeExternal(ObjectOutput out) throws IOException
{
    GraphIOUtil.writeDelimitedTo(out, this, this);
}

>>

message_impl_message(message, options) ::= <<
// message method

public Schema\<\> cachedSchema()
{
    return DEFAULT_INSTANCE;
}

>>

message_impl_schema(message, options) ::= <<
// schema methods

public  newMessage()
{
    return new ();
}

public Class\<\> typeClass()
{
    return .class;
}

public String messageName()
{
    return .class.getSimpleName();
}

public String messageFullName()
{
    return .class.getName();
}





>>

message_method_is_initialized(message, options) ::= <<

public boolean isInitialized( message)
{
    return 
        ;
}

public boolean isInitialized( message)
{
    return true;
}

>>

field_is_initialized(field, options, name) ::= <<

. != null

>>

message_field_merge(message, options, name) ::= <<

public void mergeFrom(Input input,  ) throws IOException
{
    for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this))
    {
        switch(number)
        {
            case 0:
                return;
            
            default:
                input.handleUnknownField(number, this);
        }   
    }
}

>>

field_merge_switch(field, options, name) ::= <<
case :
    
    
    
>>

singular_field_merge_switch(field, options, name) ::= <<

. = input.mergeObject(., .getSchema());
break;

. = .valueOf(input.readEnum());
break;

. = input.read();
break;

>>

repeated_field_merge_switch(field, options, name) ::= <<

if(. == null)
    . = new ArrayList\<\>();
..add(input.mergeObject(null, .getSchema()));
break;

if(. == null)
    . = new ArrayList\<\>();
..add(.valueOf(input.readEnum()));
break;

if(. == null)
    . = new ArrayList\<\>();
..add(input.read());
break;

>>

message_field_write(message, options, name) ::= <<

public void writeTo(Output output,  ) throws IOException
{
    
}

>>

field_write_switch(field, options, name) ::= <<





>>

singular_field_write_switch(field, options, name) ::= <<

if(. == null)
    throw new UninitializedMessageException();

output.writeObject(, ., .getSchema(), false);

output.writeEnum(, ..number, false);

output.write(, ., false);




     output.writeObject(, ., .getSchema(), false);


     output.writeEnum(, ..number, false);


    output.write(, ., false);


>>

repeated_field_write_switch(field, options, name) ::= <<

if(. != null)
{
    for(  : .)
    {
        if( != null)
            output.writeObject(, , .getSchema(), true);
    }
}

if(. != null)
{
    for(  : .)
    {
        if( != null)
            output.writeEnum(, .number, true);
    }
}

if(. != null)
{
    for(  : .)
    {
        if( != null)
            output.write(, , true);
    }
}

>>

singular_field_write_check(field, options) ::= <<




if(. != DEFAULT_)

if(. != null && . != DEFAULT_)


if(. != null && . != DEFAULT_)


if(. != null)




if(. != 0)

if(. != null)


if(. != null)


>>

message_field_map(message, options) ::= <<

public String getFieldName(int number)
{
    switch(number)
    {
        
        default: return null;
    }
}

public int getFieldNumber(String name)
{
    final Integer number = __fieldMap.get(name);
    return number == null ? 0 : number.intValue();
}

private static final java.util.HashMap\ __fieldMap = new java.util.HashMap\();
static
{
    
}

public String getFieldName(int number)
{
    return Integer.toString(number);
}

public int getFieldNumber(String name)
{
    return Integer.parseInt(name);
}

>>

field_switch_case(field, options) ::= <<

case : return "f";

case : return "";

>>

field_map(field, options, mapVar) ::= <<

.put("f", );

.put("", );

>>

message_static_schema_ref(message, options) ::= <<
DEFAULT_INSTANCE
>>

message_pipe_schema(message, options) ::= <<
static final Pipe.Schema\<\> PIPE_SCHEMA = new Pipe.Schema\<\>()
{
    protected void transfer(Pipe pipe, Input input, Output output) throws IOException
    {
        for(int number = input.readFieldNumber(wrappedSchema);; number = input.readFieldNumber(wrappedSchema))
        {
            switch(number)
            {
                case 0:
                    return;
                
                default:
                    input.handleUnknownField(number, wrappedSchema);
            }
        }
    }
};

public static Pipe.Schema\<\> getPipeSchema()
{
    return PIPE_SCHEMA;
}

>>

field_transfer_switch(field, options) ::= <<
case :
    
>>

field_transfer_switch_body(field, options) ::= <<

output.writeObject(number, pipe, .getPipeSchema(), );
break;

output.writeEnum(number, input.readEnum(), ); 
break;

input.transferByteRangeTo(output, true, number, );
break;

input.transferByteRangeTo(output, false, number, );
break;

output.write(number, input.read(), );
break;

>>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy