aboutsummaryrefslogtreecommitdiff
path: root/cs-dotnet/src/gatsobject.cs
blob: 792db6ae84e0caa0bd9dbe91317926c1bc05a8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.IO;

namespace Com.Xagasoft.Gats
{
    public abstract class GatsObject
    {
        public abstract void Read( Stream s, char type );
        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 ret = null;
            switch( type )
            {
                case 'i':
                    ret = new GatsInteger();
                    break;

                case 's':
                    ret = new GatsString();
                    break;

                case '0':
                case '1':
                    ret = new GatsBoolean();
                    break;

                case 'l':
                    ret = new GatsList();
                    break;

                case 'd':
                    ret = new GatsDictionary();
                    break;

                case 'f':
                case 'F':
                    ret = new GatsFloat();
                    break;

                case 'n':
                    ret = new GatsNull();
                    break;

                case 'e':
                    return null;

                default:
                    throw new GatsException( GatsException.Type.InvalidType );
	    	}

    		ret.Read( s, type );

            return ret;
        }
    }
}