www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - why there is no TBase in thrift for dlang?

reply "zhmt" <zhmtzhmt qq.com> writes:
I am writing code below:
private Cmd deserialCmd(ubyte[] data)
	{
		Cmd ret;
		TMemoryBuffer trans = new TMemoryBuffer(data);
		auto prot = new TCompactProtocol!TMemoryBuffer(trans);
		ret.read(prot);
		return ret;
	}

If I have diffrent Cmd, I have to repeat the code above,

TBase has methods like write(protocol) read(protocol), if it 
exists in thrift for dlang, I could write like this:

private TBase deserialCmd(ubyte[] data,TBase ret)
	{
		TMemoryBuffer trans = new TMemoryBuffer(data);
		auto prot = new TCompactProtocol!TMemoryBuffer(trans);
		ret.read(prot);
		return ret;
	}

But TBase doesnt exists in thrift for dlang, what can i do now?
Jan 27 2015
parent reply "zhmt" <zhmtzhmt qq.com> writes:
I resovled it by Generic programming :

	private const (ubyte)[] serialObj(T) (T obj)
	{
		TMemoryBuffer trans = new TMemoryBuffer();
		auto prot = new TCompactProtocol!TMemoryBuffer(trans);
		obj.write(prot);
		return trans.getContents();
	}
Jan 27 2015
parent "zhmt" <zhmtzhmt qq.com> writes:
sorry , I am quite new to dlang.
Jan 27 2015