///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //先写入当前对象长度占位符 int _startOffset_ = _offset_; XBuffer.WriteInt(0, _buffer_, ref _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(9, _buffer_, ref _offset_); //写入数据 XBuffer.WriteLong(id_f, _buffer_, ref _offset_); XBuffer.WriteString(s1, _buffer_, ref _offset_); XBuffer.WriteInt(i1, _buffer_, ref _offset_); XBuffer.WriteBool(b1, _buffer_, ref _offset_); XBuffer.WriteFloat(f1, _buffer_, ref _offset_); XBuffer.WriteShort(s2, _buffer_, ref _offset_); XBuffer.WriteDouble(d1, _buffer_, ref _offset_); XBuffer.WriteBytes(b2, _buffer_, ref _offset_); XBuffer.WriteString(o1, _buffer_, ref _offset_); //覆盖当前对象长度 XBuffer.WriteInt(_offset_ - _startOffset_, _buffer_, ref _startOffset_); return(_offset_); }
internal EmitInstanceBuffer(XBuffer buf, XType et, bool embed) { this.buf = buf; this.et = et; this.embed = embed; this.ranges = new List <IndexRange>(); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { sdkToken = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { handToken = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } }while(false); return(_offset_); }
internal XArrayGeneric(XType type) : base(type) { dataBuf = null; dataOff = 0; dataLen = 0; }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //先写入当前对象长度占位符 int _startOffset_ = _offset_; XBuffer.WriteInt(0, _buffer_, ref _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(12, _buffer_, ref _offset_); //写入数据 XBuffer.WriteLong(roleId, _buffer_, ref _offset_); XBuffer.WriteString(roleName, _buffer_, ref _offset_); XBuffer.WriteInt(level, _buffer_, ref _offset_); XBuffer.WriteInt(vipLevel, _buffer_, ref _offset_); XBuffer.WriteLong(fightPower, _buffer_, ref _offset_); XBuffer.WriteLong(guildId, _buffer_, ref _offset_); XBuffer.WriteString(guildName, _buffer_, ref _offset_); XBuffer.WriteInt(openServerDays, _buffer_, ref _offset_); XBuffer.WriteInt(serverLevel, _buffer_, ref _offset_); XBuffer.WriteLong(loginTick, _buffer_, ref _offset_); XBuffer.WriteLong(createTick, _buffer_, ref _offset_); XBuffer.WriteBool(isGMRole, _buffer_, ref _offset_); //覆盖当前对象长度 XBuffer.WriteInt(_offset_ - _startOffset_, _buffer_, ref _startOffset_); return(_offset_); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { result = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { reason = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 2) { hasRole = XBuffer.ReadBool(_buffer_, ref _offset_); if (hasRole) { var _idx_ = XBuffer.ReadByte(_buffer_, ref _offset_); role = new RoleInfo(); _offset_ = role.Read(_buffer_, _offset_); } } else { break; } if (_fieldNum_ > 3) { userName = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 4) { isNewCreate = XBuffer.ReadBool(_buffer_, ref _offset_); } else { break; } }while(false); return(_offset_); }
public void LoadData(byte[] data, ref int offset) { t_id = XBuffer.ReadInt(data, ref offset); m_t_mult = XBuffer.ReadInt(data, ref offset); t_str = XBuffer.ReadString(data, ref offset); t_str2 = XBuffer.ReadString(data, ref offset); t_int = XBuffer.ReadInt(data, ref offset); t_int2 = XBuffer.ReadInt(data, ref offset); t_long = XBuffer.ReadLong(data, ref offset); }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(0, _buffer_, ref _offset_); //写入数据 return(_offset_); }
internal void Init(int len) { XType xt = ObjectType; if (xt.IsRestricted) { if (xt == XType.BOOL) { dataBuf = new XBufferBool(len); } else if (xt == XType.U8) { dataBuf = new XBufferU8(len); } else if (xt == XType.U16) { dataBuf = new XBufferU16(len); } else if (xt == XType.U32) { dataBuf = new XBufferU32(len); } else if (xt == XType.U64) { dataBuf = new XBufferU64(len); } else if (xt == XType.I8) { dataBuf = new XBufferI8(len); } else if (xt == XType.I16) { dataBuf = new XBufferI16(len); } else if (xt == XType.I32) { dataBuf = new XBufferI32(len); } else if (xt == XType.I64) { dataBuf = new XBufferI64(len); } else { throw new Exception(string.Format("unknown restricted type: {0}", xt.Name)); } } else { dataBuf = new XBufferGen(len); } dataOff = 0; dataLen = len; }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(1, _buffer_, ref _offset_); //写入数据 XBuffer.WriteLong(timeTick, _buffer_, ref _offset_); return(_offset_); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); int _startOffset_ = _offset_; int _toReadLength_ = XBuffer.ReadInt(_buffer_, ref _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { l1 = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { short _count_ = XBuffer.ReadShort(_buffer_, ref _offset_); for (int _a_ = 0; _a_ < _count_; ++_a_) { l2.Add(XBuffer.ReadString(_buffer_, ref _offset_)); } } else { break; } if (_fieldNum_ > 2) { short _count_ = XBuffer.ReadShort(_buffer_, ref _offset_); for (int _a_ = 0; _a_ < _count_; ++_a_) { l3.Add(XBuffer.ReadFloat(_buffer_, ref _offset_)); } } else { break; } if (_fieldNum_ > 3) { short _count_ = XBuffer.ReadShort(_buffer_, ref _offset_); for (int _a_ = 0; _a_ < _count_; ++_a_) { var _idx_ = XBuffer.ReadByte(_buffer_, ref _offset_); if (_idx_ <= 0) { l4.Add(default);
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { }while(false); return(_offset_); }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(2, _buffer_, ref _offset_); //写入数据 XBuffer.WriteString(sdkToken, _buffer_, ref _offset_); XBuffer.WriteLong(handToken, _buffer_, ref _offset_); return(_offset_); }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(3, _buffer_, ref _offset_); //写入数据 XBuffer.WriteString(msg, _buffer_, ref _offset_); XBuffer.WriteInt(msgLanId, _buffer_, ref _offset_); XBuffer.WriteShort(type, _buffer_, ref _offset_); return(_offset_); }
internal void InitSub(XArrayGeneric src, int off, int len) { if (src.dataBuf == null) { throw new Exception("making sub-view of uninitialized array"); } if (off < 0 || off > src.dataLen || len < 0 || len > (src.dataLen - off)) { throw new Exception(string.Format("sub-view ({0},{1}) does not fit in source array length {2}", off, len, src.dataLen)); } this.dataBuf = src.dataBuf; this.dataOff = src.dataOff + off; this.dataLen = len; }
internal static void PrintArray( TextWriter tw, int indent, XArrayGeneric xag) { XType xt = xag.ObjectType; tw.WriteLine("{"); Compiler.Indent(tw, indent + 1); tw.WriteLine("(void *)&t1t_{0},", Compiler.Encode(xt.Name)); XBuffer xb = xag.dataBuf; if (xb == null) { /* * Uninitialized array. */ Compiler.Indent(tw, indent + 1); tw.WriteLine("0, 0, 0"); } else { EmitInstance ei; if (!toEmit.TryGetValue(xb, out ei)) { throw new Exception("internal error: buffer is not scheduled for emission"); } EmitInstanceBuffer eib = ei as EmitInstanceBuffer; if (eib == null) { throw new Exception("buffer not associated with EmitInstanceBuffer"); } int range; int off; eib.FindRange(xag.dataOff, out range, out off); Compiler.Indent(tw, indent + 1); tw.WriteLine("(void *)&t1b_{0}_{1},", xb.Serial, range); Compiler.Indent(tw, indent + 1); tw.WriteLine("{0},", off); Compiler.Indent(tw, indent + 1); tw.WriteLine("{0}", xag.dataLen); } Compiler.Indent(tw, indent); tw.Write("}"); }
static EmitInstanceBuffer AddBuffer(XBuffer xb, XType et, bool embed, int off, int len) { EmitInstanceBuffer eib; EmitInstance ei; if (toEmit.TryGetValue(xb, out ei)) { eib = ei as EmitInstanceBuffer; if (eib == null) { throw new Exception(string.Format("buffer not associated with an appropriate EmitInstanceBuffer")); } } else { eib = new EmitInstanceBuffer(xb, et, embed); toEmit[xb] = eib; } eib.AddRange(off, len); /* * All values in the referenced range must be added. */ if (embed) { for (int i = 0; i < len; i++) { int j = off + i; AddInstance(xb.Get(j).XObject, eib, j); } } else { for (int i = 0; i < len; i++) { int j = off + i; AddValueInner(xb.Get(j)); } } return(eib); }
public void LoadData(byte[] data, ref int offset) { string useField = "t_" + Settings.Ins.Language; t_id = XBuffer.ReadInt(data, ref offset); if (string.IsNullOrEmpty(t_content) && useField == "t_chinese") { t_content = XBuffer.ReadString(data, ref offset); } else { //不需要的语言字段跳过 short slen = XBuffer.ReadShort(data, ref offset); offset += slen; } if (string.IsNullOrEmpty(t_content) && useField == "t_chinesetraditional") { t_content = XBuffer.ReadString(data, ref offset); } else { //不需要的语言字段跳过 short slen = XBuffer.ReadShort(data, ref offset); offset += slen; } if (string.IsNullOrEmpty(t_content) && useField == "t_english") { t_content = XBuffer.ReadString(data, ref offset); } else { //不需要的语言字段跳过 short slen = XBuffer.ReadShort(data, ref offset); offset += slen; } }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { success = XBuffer.ReadBool(_buffer_, ref _offset_); } else { break; } }while(false); return(_offset_); }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(5, _buffer_, ref _offset_); //写入数据 XBuffer.WriteInt(result, _buffer_, ref _offset_); XBuffer.WriteInt(reason, _buffer_, ref _offset_); XBuffer.WriteBool(hasRole, _buffer_, ref _offset_); if (hasRole) { XBuffer.WriteByte(role._msgIdx_, _buffer_, ref _offset_); _offset_ = role.Write(_buffer_, _offset_); } XBuffer.WriteString(userName, _buffer_, ref _offset_); XBuffer.WriteBool(isNewCreate, _buffer_, ref _offset_); return(_offset_); }
///<summary>序列化,写入数据</summary> public override int Write(byte[] _buffer_, int _offset_) { _offset_ = base.Write(_buffer_, _offset_); //写入字段数量,最多支持255个 XBuffer.WriteByte(12, _buffer_, ref _offset_); //写入数据 XBuffer.WriteString(userName, _buffer_, ref _offset_); XBuffer.WriteInt(serverId, _buffer_, ref _offset_); XBuffer.WriteString(sdkToken, _buffer_, ref _offset_); XBuffer.WriteInt(sdkType, _buffer_, ref _offset_); XBuffer.WriteString(channelId, _buffer_, ref _offset_); XBuffer.WriteBool(isRelogin, _buffer_, ref _offset_); XBuffer.WriteLong(handToken, _buffer_, ref _offset_); XBuffer.WriteInt(deviceType, _buffer_, ref _offset_); XBuffer.WriteString(deviceOS, _buffer_, ref _offset_); XBuffer.WriteString(deviceModel, _buffer_, ref _offset_); XBuffer.WriteString(deviceName, _buffer_, ref _offset_); XBuffer.WriteString(deviceId, _buffer_, ref _offset_); return(_offset_); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { msg = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { msgLanId = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 2) { type = XBuffer.ReadShort(_buffer_, ref _offset_); } else { break; } }while(false); return(_offset_); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { userName = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { serverId = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 2) { sdkToken = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 3) { sdkType = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 4) { channelId = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 5) { isRelogin = XBuffer.ReadBool(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 6) { handToken = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 7) { deviceType = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 8) { deviceOS = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 9) { deviceModel = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 10) { deviceName = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 11) { deviceId = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } }while(false); return(_offset_); }
internal void Init(XBuffer dataBuf, int dataOff, int dataLen) { this.dataBuf = dataBuf; this.dataOff = dataOff; this.dataLen = dataLen; }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); int _startOffset_ = _offset_; int _toReadLength_ = XBuffer.ReadInt(_buffer_, ref _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { roleId = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { roleName = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 2) { level = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 3) { vipLevel = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 4) { fightPower = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 5) { guildId = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 6) { guildName = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 7) { openServerDays = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 8) { serverLevel = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 9) { loginTick = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 10) { createTick = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 11) { isGMRole = XBuffer.ReadBool(_buffer_, ref _offset_); } else { break; } }while(false); //剔除多余数据 if (_offset_ < _toReadLength_ - _startOffset_) { _offset_ += _toReadLength_ - _startOffset_; } return(_offset_); }
///<summary>反序列化,读取数据</summary> public override int Read(byte[] _buffer_, int _offset_) { _offset_ = base.Read(_buffer_, _offset_); int _startOffset_ = _offset_; int _toReadLength_ = XBuffer.ReadInt(_buffer_, ref _offset_); //字段个数,最多支持255个 var _fieldNum_ = XBuffer.ReadByte(_buffer_, ref _offset_); do { if (_fieldNum_ > 0) { id_f = XBuffer.ReadLong(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 1) { s1 = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 2) { i1 = XBuffer.ReadInt(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 3) { b1 = XBuffer.ReadBool(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 4) { f1 = XBuffer.ReadFloat(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 5) { s2 = XBuffer.ReadShort(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 6) { d1 = XBuffer.ReadDouble(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 7) { b2 = XBuffer.ReadBytes(_buffer_, ref _offset_); } else { break; } if (_fieldNum_ > 8) { o1 = XBuffer.ReadString(_buffer_, ref _offset_); } else { break; } }while(false); //剔除多余数据 if (_offset_ < _toReadLength_ - _startOffset_) { _offset_ += _toReadLength_ - _startOffset_; } return(_offset_); }