blob: 07f9be827c054a0cb3e82ae2f1afd2a6b49b80fa (
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* Copyright (C) 2007-2013 Xagasoft, All rights reserved.
*
* This file is part of the libgats library and is released under the
* terms of the license contained in the file LICENSE.
*/
using System;
using System.IO;
using Com.Xagasoft.Gats;
public class Test
{
public static void Write( GatsObject o, Stream s )
{
GatsStream gs = new GatsStream( s );
gs.WriteObject( o );
Console.WriteLine("Wrote: " + o );
}
public static GatsObject Read( Stream s )
{
GatsStream gs = new GatsStream( s );
GatsObject o = gs.ReadObject();
if( o == null )
Console.WriteLine("Nothing Read");
else
{
Console.WriteLine("Read type: " + o.GetType() );
Console.WriteLine("Read value: " + o );
}
return o;
}
public static void Main()
{
MemoryStream ms = new MemoryStream();
GatsDictionary d = new GatsDictionary();
GatsList l = new GatsList();
l.Add( new GatsFloat( Math.PI ) );
l.Add( new GatsInteger( 1337 ) );
l.Add( new GatsString("Hello") );
d.Add("list", l );
d.Add("int", new GatsInteger( 998877 ) );
d.Add("float", new GatsFloat( 87.332 ) );
d.Add("string", new GatsString("Yup, a string") );
d.Add("bool", new GatsBoolean( false ) );
Write( d, ms );
ms.Seek( 0, SeekOrigin.Begin );
Read( ms );
try
{
FileStream fs = new FileStream("packet.gats", FileMode.Open,
FileAccess.Read );
Console.WriteLine("===Reading from file===");
GatsStream gs = new GatsStream( fs );
GatsObject o = null;
do
{
o = gs.ReadObject();
if( o == null )
Console.WriteLine("Nothing Read");
else
{
Console.WriteLine("Read type: " + o.GetType() );
Console.WriteLine("Read value: " + o );
}
} while( o != null );
}
catch( Exception e )
{
Console.WriteLine("Can't test files: " + e.Message );
Console.WriteLine( e );
}
}
}
|