From 63628550708a616c5c58bc5c707db1e7fd9cd7c2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 14 Nov 2012 23:55:29 +0000 Subject: Strings, bools, and ints all seem fine, the more complex container types are coming next, and will implement the full range of appropriate interfaces. --- cs-dotnet/src/gatsobject.cs | 53 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'cs-dotnet/src/gatsobject.cs') diff --git a/cs-dotnet/src/gatsobject.cs b/cs-dotnet/src/gatsobject.cs index f782f95..a0b9276 100644 --- a/cs-dotnet/src/gatsobject.cs +++ b/cs-dotnet/src/gatsobject.cs @@ -4,7 +4,58 @@ namespace Com.Xagasoft.Gats { public abstract class GatsObject { - public abstract void Read( Stream s, byte cType ); + public abstract void Read( Stream s, char cType ); public abstract void Write( Stream s ); + + public static GatsObject Read( Stream s ) + { + int b = s.ReadByte(); + if( b == -1 ) + throw new GatsException( GatsException.Type.PrematureEnd ); + char type = (char)b; + GatsObject goRet = null; + switch( type ) + { + case 'i': + goRet = new GatsInteger(); + break; + + case 's': + goRet = new GatsString(); + break; + + case '0': + case '1': + goRet = new GatsBoolean(); + break; + + case 'l': +// goRet = new GatsList(); + break; + + case 'd': +// goRet = new GatsDictionary(); + break; + + case 'f': + case 'F': +// goRet = new GatsFloat(); + break; + + case 'n': +// goRet = new GatsNull(); + break; + + case 'e': + return null; + + default: + throw new GatsException( GatsException.Type.InvalidType ); + } + + goRet.Read( s, type ); + + return goRet; + } } } -- cgit v1.2.3