using System.IO; namespace Com.Xagasoft.Gats { public class GatsString : GatsObject { public byte[] Value { get; set; } public GatsString() { } public GatsString( byte[] val ) { Value = val; } public GatsString( string val ) { Value = System.Text.Encoding.UTF8.GetBytes( val ); } public override string ToString() { return System.Text.Encoding.UTF8.GetString( Value ); } public override void Read( Stream s, char cType ) { int Size = (int)GatsInteger.ReadPackedInt( s ); Value = new byte[Size]; int SoFar = 0; do { SoFar += s.Read( Value, SoFar, Size-SoFar ); } while( SoFar < Size ); } public override void Write( Stream s ) { s.WriteByte( (byte)'s' ); if( Value == null ) { GatsInteger.WritePackedInt( s, 0 ); } else { GatsInteger.WritePackedInt( s, Value.Length ); s.Write( Value, 0, Value.Length ); } } }; }