public static ushort ReadDescDataString(ref ByteBuffer buffer, ref string text) { int dataDescLen = Marshal.SizeOf(typeof(tagDataDescribe)); if ((buffer.Length - buffer.Position) <= dataDescLen) { return(0); } byte[] descData = buffer.PopByteArray(dataDescLen); tagDataDescribe desc = GameConvert.ByteToStruct <tagDataDescribe>(descData); if (desc.wDataDescribe == CommonDefine.DTP_NULL) { return(0); } byte[] data = buffer.PopByteArray(desc.wDataSize); text = System.Text.Encoding.Unicode.GetString(data); if (text.Length > 0) { text = text.Substring(0, text.IndexOf((char)0)); } return(desc.wDataDescribe); }
public static bool AppendDescDataString(ref ByteBuffer buffer, ushort type, string text) { byte[] textBytes = System.Text.Encoding.Unicode.GetBytes(text); tagDataDescribe desc = new tagDataDescribe(); desc.wDataDescribe = type; desc.wDataSize = (ushort)textBytes.Length; byte[] descBytes = GameConvert.StructToByteArray <tagDataDescribe>(desc); buffer.PushByteArray(descBytes); buffer.PushByteArray(textBytes); return(true); }