private TagNode ReadString() { byte[] lenBytes = new byte[2]; _stream.Read(lenBytes, 0, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); } short len = BitConverter.ToInt16(lenBytes, 0); if (len < 0) { throw new NBTException(NBTException.MSG_READ_NEG); } byte[] strBytes = new byte[len]; _stream.Read(strBytes, 0, len); System.Text.Encoding str = Encoding.UTF8; TagNodeString val = new TagNodeString(str.GetString(strBytes)); return(val); }
private bool VerifyString(TagNode tag, SchemaNodeString schema) { TagNodeString stag = tag as TagNodeString; if (stag == null) { if (!OnInvalidTagType(new TagEventArgs(schema, tag))) { return(false); } } if (schema.Length > 0 && stag.Length > schema.Length) { if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) { return(false); } } if (schema.Value != null && stag.Data != schema.Value) { if (!OnInvalidTagValue(new TagEventArgs(schema, tag))) { return(false); } } return(true); }
private void WriteString(TagNodeString val) { System.Text.Encoding str = Encoding.UTF8; byte[] gzBytes = str.GetBytes(val.Data); byte[] lenBytes = BitConverter.GetBytes((short)gzBytes.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); } _stream.Write(lenBytes, 0, 2); _stream.Write(gzBytes, 0, gzBytes.Length); }