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 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 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); }
public void Write(TarsStruct o, int tag) { if (o == null) { return; } reserve(2); writeHead((byte)TarsStructType.STRUCT_BEGIN, tag); o.WriteTo(this); reserve(2); writeHead((byte)TarsStructType.STRUCT_END, 0); }
public void Write(TarsStruct s, int tag) { if (s == null) { return; } Reserve(2); WriteHead((byte)TarsStructType.STRUCT_BEGIN, tag); s.WriteTo(this); Reserve(2); WriteHead((byte)TarsStructType.STRUCT_END, 0); }
public TarsDisplayer Display(TarsStruct v, string fieldName) { Display('{', fieldName); if (null == v) { sb.Append('\t').Append("null"); } else { v.Display(sb, _level + 1); } Display('}', null); return(this); }