public TarsStruct Read(TarsStruct s, int tag, bool isRequire) { // TarsStruct must have a no-argument constructor. TarsStruct ref_s = null; if (SkipToTag(tag)) { try { // Must be recreated, otherwise it will result in assignment on the same object, // which is caused by a reference to C#. ref_s = (TarsStruct)BasicClassTypeUtil.CreateObject(s.GetType()); } catch (Exception ex) { throw new TarsDecodeException(ex.Message); } HeadData head = new HeadData(); ReadHead(head); if (head.type != (byte)TarsStructType.STRUCT_BEGIN) { throw new TarsDecodeException("type mismatch."); } ref_s.ReadFrom(this); SkipToStructEnd(); } else if (isRequire) { throw new TarsDecodeException("require field not exist."); } return(ref_s); }
public TarsStruct Read(TarsStruct o, int tag, bool isRequire) { //o必须有一个无参的构造函数 TarsStruct reff = null; if (skipToTag(tag)) { try { // 必须重新创建一个,否则,会导致在同一个对象上赋值,这是由于C#的引用引起的 reff = (TarsStruct)BasicClassTypeUtil.CreateObject(o.GetType()); } catch (Exception e) { throw new TarsDecodeException(e.Message); } HeadData hd = new HeadData(); readHead(hd); if (hd.type != (byte)TarsStructType.STRUCT_BEGIN) { throw new TarsDecodeException("type mismatch."); } reff.ReadFrom(this); skipToStructEnd(); } else if (isRequire) { throw new TarsDecodeException("require field not exist."); } return(reff); }
public TarsStruct DirectRead(TarsStruct s, int tag, bool isRequire) { // TarsStruct must have a no-argument constructor. TarsStruct ref_s = null; if (SkipToTag(tag)) { try { ref_s = (TarsStruct)BasicClassTypeUtil.CreateObject(s.GetType()); } catch (Exception ex) { throw new TarsDecodeException(ex.Message); } HeadData head = new HeadData(); ReadHead(head); if (head.type != (byte)TarsStructType.STRUCT_BEGIN) { throw new TarsDecodeException("type mismatch."); } ref_s.ReadFrom(this); SkipToStructEnd(); } else if (isRequire) { throw new TarsDecodeException("require field not exist."); } return(ref_s); }