diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-14 23:55:29 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-14 23:55:29 +0000 |
| commit | 63628550708a616c5c58bc5c707db1e7fd9cd7c2 (patch) | |
| tree | b6b7d466db687ba360cd760245d1146e973863c0 /cs-dotnet/src/gatsstring.cs | |
| parent | 9d86cba840252b451c4b86d9ea16c821b6c97245 (diff) | |
| download | libgats-63628550708a616c5c58bc5c707db1e7fd9cd7c2.tar.gz libgats-63628550708a616c5c58bc5c707db1e7fd9cd7c2.tar.bz2 libgats-63628550708a616c5c58bc5c707db1e7fd9cd7c2.tar.xz libgats-63628550708a616c5c58bc5c707db1e7fd9cd7c2.zip | |
Strings, bools, and ints all seem fine, the more complex container types are
coming next, and will implement the full range of appropriate interfaces.
Diffstat (limited to 'cs-dotnet/src/gatsstring.cs')
| -rw-r--r-- | cs-dotnet/src/gatsstring.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cs-dotnet/src/gatsstring.cs b/cs-dotnet/src/gatsstring.cs new file mode 100644 index 0000000..30b0afb --- /dev/null +++ b/cs-dotnet/src/gatsstring.cs | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | using System.IO; | ||
| 2 | |||
| 3 | namespace Com.Xagasoft.Gats | ||
| 4 | { | ||
| 5 | public class GatsString : GatsObject | ||
| 6 | { | ||
| 7 | public byte[] Value { get; set; } | ||
| 8 | |||
| 9 | public GatsString() | ||
| 10 | { | ||
| 11 | } | ||
| 12 | |||
| 13 | public GatsString( byte[] val ) | ||
| 14 | { | ||
| 15 | Value = val; | ||
| 16 | } | ||
| 17 | |||
| 18 | public override string ToString() | ||
| 19 | { | ||
| 20 | return Value.ToString(); | ||
| 21 | } | ||
| 22 | |||
| 23 | public override void Read( Stream s, char cType ) | ||
| 24 | { | ||
| 25 | int Size = (int)GatsInteger.ReadPackedInt( s ); | ||
| 26 | Value = new byte[Size]; | ||
| 27 | int SoFar = 0; | ||
| 28 | do | ||
| 29 | { | ||
| 30 | SoFar += s.Read( Value, SoFar, Size-SoFar ); | ||
| 31 | } while( SoFar < Size ); | ||
| 32 | } | ||
| 33 | |||
| 34 | public override void Write( Stream s ) | ||
| 35 | { | ||
| 36 | s.WriteByte( (byte)'s' ); | ||
| 37 | if( Value == null ) | ||
| 38 | { | ||
| 39 | GatsInteger.WritePackedInt( s, 0 ); | ||
| 40 | } | ||
| 41 | else | ||
| 42 | { | ||
| 43 | GatsInteger.WritePackedInt( s, Value.Length ); | ||
| 44 | s.Write( Value, 0, Value.Length ); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | } | ||
| 49 | |||
