Ejemplo n.º 1
0
static void generateFieldContainerSCode(CodeFile& f, FieldContainer* fc)
{
    for (size_t i = 0; i < fc->fields_.size(); i++)
    {
        Field& field = fc->fields_[i];
        if (field.isArray())
            f.output("BTK_Writer.type_array(BTK_Writer.type_%s, v.%s, b)", getFieldTypeName(field), field.getNameC());
        else
            f.output("BTK_Writer.type_%s(v.%s, b)", getFieldTypeName(field), field.getNameC());
    }
}
Ejemplo n.º 2
0
static void generateMethodDispatcher(CodeFile& f, Service* s, Method& m)
{
	f.output("public static bool %s(bintalk.IReader __r__, %sProxy __p__)", m.getNameC(), s->getNameC());
	f.indent("{");
	for(size_t i = 0; i < m.fields_.size(); i++)
	{
		Field& field = m.fields_[i];
		std::string tn;
		getFieldTypeName(field, tn); 
		std::string dft;
		getFieldDefault(field, dft);
		f.output("%s %s= %s;", 
			tn.c_str(),
			field.getNameC(),
			dft.c_str());
	}
	generateFieldContainerDSCode(f, &m);
	f.listBegin(",", false, "return __p__.%s(", m.getNameC());
	for(size_t i = 0; i < m.fields_.size(); i++)
	{
		Field& field = m.fields_[i];
		f.listItem("%s", field.getNameC());
	}
	f.listEnd(");");
	f.recover("}");
}
Ejemplo n.º 3
0
static void generateFieldContainerDSCode(CodeFile& f, FieldContainer* fc)
{
    for (size_t i = 0; i < fc->fields_.size(); i++)
    {
        Field& field = fc->fields_[i];
        if (field.isArray())
            f.output("v.%s, p = BTK_Reader.type_array(b, p, BTK_Reader.type_%s, 0X%X, 0X%X)", field.getNameC(), getFieldTypeName(field), field.maxArray_, field.maxValue_);
        else
            f.output("v.%s, p = BTK_Reader.type_%s(b, p, 0X%X)", field.getNameC(), getFieldTypeName(field), field.maxValue_);
    }
}
Ejemplo n.º 4
0
static void generateProxyAbstractMethod(CodeFile& f, Method& m)
{
	f.listBegin(",", false, "bool %s(", m.getNameC());
	for(size_t i = 0; i < m.fields_.size(); i++)
	{
		Field& field = m.fields_[i];
		std::string tn;
		getFieldTypeName(field, tn); 
		f.listItem("%s %s",tn.c_str(), field.getNameC());
	}
	f.listEnd(");");
}
Ejemplo n.º 5
0
static void getFieldDefault(Field& f, std::string& name)
{
	if(f.isArray())
	{
		name = "new ";
		std::string tn;
		getFieldTypeName(f, tn);
		name += tn;
		name += "()";
	}
	else
		getFieldInnerDefault(f, name);
}
Ejemplo n.º 6
0
static void generateFieldContainerSCode(CodeFile& f, FieldContainer* fc, bool self)
{
	for(size_t i = 0; i < fc->fields_.size(); i++)
	{
		Field& field = fc->fields_[i];
		f.output("protocol_writer.write(protocol_writer.type_%s, %s, %s%s, __b__)",
			getFieldTypeName(field),
			field.isArray()?"True":"False",
			self?"self.":"",
			field.getNameC()
			);
	}
}
Ejemplo n.º 7
0
static void generateFieldContainerDSCode(CodeFile& f, FieldContainer* fc, bool self)
{
	for(size_t i = 0; i < fc->fields_.size(); i++)
	{
		Field& field = fc->fields_[i];
		f.output("%s%s, __p__= protocol_reader.read(__b__, __p__, protocol_reader.type_%s, 0X%X, 0X%X)",
			self?"self.":"",
			field.getNameC(),
			getFieldTypeName(field),
			field.maxArray_,
			field.maxValue_
			);
	}
}
Ejemplo n.º 8
0
static void generateStruct(CodeFile& f, Struct* s)
{
	f.output("public class %s", s->getNameC());
	f.indent("{");
	// fields.
	for(size_t i = 0; i < s->fields_.size(); i++)
	{
		Field& field = s->fields_[i];
		std::string tn;
		getFieldTypeName(field, tn);
		std::string dft;
		getFieldDefault(field, dft);
		f.output("public %s %s= %s;", 
			tn.c_str(),
			field.getNameC(),
			dft.c_str());
	}
	// serialize code.
	f.output("public void serialize(bintalk.IWriter __w__)");
	f.indent("{");
	generateFieldContainerSCode(f, s);
	f.recover("}");
	// deserialize code.
	f.output("public bool deserialize(bintalk.IReader __r__)");
	f.indent("{");
	generateFieldContainerDSCode(f, s);
	f.output("return true;");
	f.recover("}");
	f.recover("}");
	////////////////////////////////////////////////////////////////////////////////
	f.output("namespace bintalk");
	f.indent("{");
	f.output("public static partial class ProtocolReader");
	f.indent("{");
	f.output("public static bool read(bintalk.IReader r, ref %s v, uint maxValue)", s->getNameC());
	f.indent("{");
	f.output("return v.deserialize(r);");
	f.recover("}");
	f.recover("}");
	f.output("public static partial class ProtocolWriter");
	f.indent("{");
	f.output("public static void write(bintalk.IWriter w, %s v)", s->getNameC());
	f.indent("{");
	f.output("v.serialize(w);");
	f.recover("}");
	f.recover("}");
	f.recover("}");
}
Ejemplo n.º 9
0
static void generateStubMethod(CodeFile& f, Service* s, Method& m)
{
	f.listBegin(",", false, "public void %s(", m.getNameC());
	for(size_t i = 0; i < m.fields_.size(); i++)
	{
		Field& field = m.fields_[i];
		std::string tn;
		getFieldTypeName(field, tn); 
		f.listItem("%s %s", tn.c_str(), field.getNameC());
	}
	f.listEnd(")");
	f.indent("{");
	f.output("bintalk.IWriter __w__ = methodBegin();");
	f.output("bintalk.ProtocolWriter.writeMid(__w__, %d);", m.mid_);
	generateFieldContainerSCode(f, &m);
	f.output("methodEnd();");
	f.recover("}");
}
Ejemplo n.º 10
0
Handle<Value> FieldDefn::typeGetter(Local<String> property, const AccessorInfo &info)
{
	HandleScope scope;
	FieldDefn *def = ObjectWrap::Unwrap<FieldDefn>(info.This());
	return scope.Close(SafeString::New(getFieldTypeName(def->this_->GetType())));
}