public void WriteString(string val) { Utils.Log("Writing string: " + val + " at pos " + size.ToString(), 2); if (val == null || val.Length <= 0) { byte len = 0; writer.Write(len); size++; } else { TERRAString2 temp = new TERRAString2(val); int len = temp.length(); byte n; if (len < 255) n = (byte)len; else n = 255; writer.Write(n); size++; if (len >= 255) { ushort pp = (ushort)len; writer.Write(pp); size += 2; } //System.Text.Encoding.ASCII.GetBytes(val); writer.Write(temp.getBytes()); size += len; } }
public string ReadString() { byte n = ReadByte(); ushort len = 0; if (n >= 255) len = ReadWord(); if (n <= 0) return null; else len = n; byte[] bytes = reader.ReadBytes(len); TERRAString2 temp = new TERRAString2(bytes); return temp.ToString(); }