public static byte[] EncodeMsg(Thrift.Protocol.TBase reqMsg) { var tmem = new Thrift.Transport.TMemoryBuffer(); var proto = new Thrift.Protocol.TBinaryProtocol(tmem); //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0)); reqMsg.Write(proto); //proto.WriteMessageEnd(); byte[] byteData = tmem.GetBuffer(); return(byteData); }
/// <summary> /// Gets bytes that represents the current object. /// </summary> /// <returns></returns> public static byte[] GetBytes <T>(T tobj) where T : TAbstractBase { using (var trans = new Thrift.Transport.TMemoryBuffer()) { using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans)) { tobj.Write(oprot); return(trans.GetBuffer()); } } }
public static bool decodeMsg <T>(T reqMsg, string strData) where T : Thrift.Protocol.TBase { byte[] data = System.Text.Encoding.UTF8.GetBytes(strData); var tmem = new Thrift.Transport.TMemoryBuffer(data); var proto = new Thrift.Protocol.TBinaryProtocol(tmem); //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0); //proto.ReadMessageBegin(); reqMsg.Read(proto); //proto.ReadMessageEnd(); return(true); }
public static string encodeMsg <T>(T reqMsg) where T : Thrift.Protocol.TBase { var tmem = new Thrift.Transport.TMemoryBuffer(); var proto = new Thrift.Protocol.TBinaryProtocol(tmem); //proto.WriteMessageBegin(new Thrift.Protocol.TMessage("ff::RegisterToBrokerReq", Thrift.Protocol.TMessageType.Call, 0)); reqMsg.Write(proto); //proto.WriteMessageEnd(); byte[] byteData = tmem.GetBuffer(); string strRet = System.Text.Encoding.UTF8.GetString(byteData, 0, byteData.Length); return(strRet); }
/// <summary> /// Creates a new instance from the byte array provided. /// </summary> /// <param name="bytes"></param> public static T CreateObject <T>(byte[] bytes) where T : TBase, new() { using (var trans = new Thrift.Transport.TMemoryBuffer(bytes)) { using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans)) { var tobj = new T(); tobj.Read(oprot); return(tobj); } } }
public static bool DecodeMsg(Thrift.Protocol.TBase reqMsg, byte[] data) { if (data.Length == 0) { return(false); } var tmem = new Thrift.Transport.TMemoryBuffer(data); var proto = new Thrift.Protocol.TBinaryProtocol(tmem); //var msgdef = new Thrift.Protocol.TMessage("ffthrift", Thrift.Protocol.TMessageType.Call, 0); //proto.ReadMessageBegin(); reqMsg.Read(proto); //proto.ReadMessageEnd(); return(true); }