diff options
Diffstat (limited to '')
-rw-r--r-- | cs-dotnet/src/gatsexception.cs | 3 | ||||
-rw-r--r-- | cs-dotnet/src/gatsobject.cs | 42 | ||||
-rw-r--r-- | cs-dotnet/src/gatsstream.cs | 57 |
3 files changed, 102 insertions, 0 deletions
diff --git a/cs-dotnet/src/gatsexception.cs b/cs-dotnet/src/gatsexception.cs index 442a4ff..1d01e07 100644 --- a/cs-dotnet/src/gatsexception.cs +++ b/cs-dotnet/src/gatsexception.cs | |||
@@ -9,6 +9,9 @@ using System; | |||
9 | 9 | ||
10 | namespace Com.Xagasoft.Gats | 10 | namespace Com.Xagasoft.Gats |
11 | { | 11 | { |
12 | /// <summary> | ||
13 | /// Exception used to report parsing or encoding errors in GATS. | ||
14 | /// </summary> | ||
12 | public class GatsException : Exception | 15 | public class GatsException : Exception |
13 | { | 16 | { |
14 | public enum Type | 17 | public enum Type |
diff --git a/cs-dotnet/src/gatsobject.cs b/cs-dotnet/src/gatsobject.cs index 7c92cff..57da747 100644 --- a/cs-dotnet/src/gatsobject.cs +++ b/cs-dotnet/src/gatsobject.cs | |||
@@ -9,11 +9,53 @@ using System.IO; | |||
9 | 9 | ||
10 | namespace Com.Xagasoft.Gats | 10 | namespace Com.Xagasoft.Gats |
11 | { | 11 | { |
12 | /// <summary> | ||
13 | /// The base class of all GATS Data Type classes. | ||
14 | /// </summary> | ||
15 | /// <remarks> | ||
16 | /// This provides the standard Read and Write methods that are used to do | ||
17 | /// all type serialization, as well as a handy static Read function that | ||
18 | /// can be used | ||
19 | /// to read in any type. These methods should not be used in normal | ||
20 | /// programming, instead use the GatsStream class to read and write | ||
21 | /// complete GATS packets. | ||
22 | /// </remarks> | ||
12 | public abstract class GatsObject | 23 | public abstract class GatsObject |
13 | { | 24 | { |
25 | /// <summary> | ||
26 | /// Read a single object from the provided stream. | ||
27 | /// </summary> | ||
28 | /// <remarks> | ||
29 | /// This method does not read the leading type character. The static | ||
30 | /// Read method in GatsObject does this, and passes the type into the | ||
31 | /// Read method as a parameter in case it's needed by a specific type, | ||
32 | /// such as GatsBoolean. | ||
33 | /// </remarks> | ||
34 | /// <param name="s">The Stream derived class to read from.</param> | ||
35 | /// <param name="type">The already read type specifier.</param> | ||
14 | public abstract void Read( Stream s, char type ); | 36 | public abstract void Read( Stream s, char type ); |
37 | |||
38 | /// <summary> | ||
39 | /// Write a single object to the provided stream. | ||
40 | /// </summary> | ||
41 | /// <remarks> | ||
42 | /// Unlike the Read method, this does actually write the leading type | ||
43 | /// specifier. | ||
44 | /// </remarks> | ||
45 | /// <param name="s">The Stream derived class to write to.</param> | ||
15 | public abstract void Write( Stream s ); | 46 | public abstract void Write( Stream s ); |
16 | 47 | ||
48 | /// <summary> | ||
49 | /// Reads a GatsObject from the provided stream and returns it. | ||
50 | /// </summary> | ||
51 | /// <remarks> | ||
52 | /// This method reads the initial type specifier byte, constructs the | ||
53 | /// proper object, calls the Read method on that object, and returns | ||
54 | /// the result. | ||
55 | /// </remarks> | ||
56 | /// <returns> | ||
57 | /// The constructed object, or null if an end type was found. | ||
58 | /// </returns> | ||
17 | public static GatsObject Read( Stream s ) | 59 | public static GatsObject Read( Stream s ) |
18 | { | 60 | { |
19 | int b = s.ReadByte(); | 61 | int b = s.ReadByte(); |
diff --git a/cs-dotnet/src/gatsstream.cs b/cs-dotnet/src/gatsstream.cs index e1bba91..742f0b4 100644 --- a/cs-dotnet/src/gatsstream.cs +++ b/cs-dotnet/src/gatsstream.cs | |||
@@ -11,6 +11,23 @@ using System; | |||
11 | 11 | ||
12 | namespace Com.Xagasoft.Gats | 12 | namespace Com.Xagasoft.Gats |
13 | { | 13 | { |
14 | /// <summary> | ||
15 | /// Main I/O interface. Use this to read and write GATS. | ||
16 | /// </summary> | ||
17 | /// <remarks> | ||
18 | /// GatsStream is not a traditional Stream class, it only can read and | ||
19 | /// write complete GATS packets. A GATS packet consists of a version, | ||
20 | /// size, and a single encoded GATS object (which can be a container). | ||
21 | /// | ||
22 | /// This one class handles both reading and writing. Writing is fairly | ||
23 | /// straight forward, but for volatile streams like network sockets you'll | ||
24 | /// probably want to wrap your stream with a buffer before handing it to | ||
25 | /// GatsStream. | ||
26 | /// | ||
27 | /// Reading handles it's own buffering, and will remember what has been | ||
28 | /// read between calls if it cannot get enough data at once to complete | ||
29 | /// a single packet. See the ReadObject docs for more details. | ||
30 | /// </remarks> | ||
14 | public class GatsStream | 31 | public class GatsStream |
15 | { | 32 | { |
16 | private Stream s; | 33 | private Stream s; |
@@ -20,12 +37,37 @@ namespace Com.Xagasoft.Gats | |||
20 | private BinaryWriter bw = null; | 37 | private BinaryWriter bw = null; |
21 | private BinaryReader br = null; | 38 | private BinaryReader br = null; |
22 | 39 | ||
40 | /// <summary> | ||
41 | /// Construct a new GatsStream around a given Stream class. | ||
42 | /// </summary> | ||
43 | /// <remarks> | ||
44 | /// The provided Stream does not need to be opened for both reading and | ||
45 | /// writing, you can construct a GatsStream around a read only or | ||
46 | /// write only stream. | ||
47 | /// </remarks> | ||
48 | /// <param name="s">Stream to operate on.</param> | ||
23 | public GatsStream( Stream s ) | 49 | public GatsStream( Stream s ) |
24 | { | 50 | { |
25 | this.s = s; | 51 | this.s = s; |
26 | this.ReadBuf = new MemoryStream(); | 52 | this.ReadBuf = new MemoryStream(); |
27 | } | 53 | } |
28 | 54 | ||
55 | /// <summary> | ||
56 | /// Read a GATS packet and return the contained GatsObject. | ||
57 | /// </summary> | ||
58 | /// <remarks> | ||
59 | /// This reads a complete packet into an internal buffer, parses the | ||
60 | /// gats object within it, and returns it. This method will read as | ||
61 | /// much data as it needs from the stream, but no more. Not a single | ||
62 | /// extra byte will be read. | ||
63 | /// | ||
64 | /// In the event that an end of stream is encountered, or a partial | ||
65 | /// packet has been read but no more data can be read at the moment, | ||
66 | /// this method will maintain it's buffer but return null to the caller. | ||
67 | /// </remarks> | ||
68 | /// <returns> | ||
69 | /// The read object, or null if no object could be read yet. | ||
70 | /// </returns> | ||
29 | public GatsObject ReadObject() | 71 | public GatsObject ReadObject() |
30 | { | 72 | { |
31 | if( size == -1 ) | 73 | if( size == -1 ) |
@@ -70,6 +112,21 @@ namespace Com.Xagasoft.Gats | |||
70 | return null; | 112 | return null; |
71 | } | 113 | } |
72 | 114 | ||
115 | /// <summary> | ||
116 | /// Write a GatsObject to the stream in a proper GATS packet. | ||
117 | /// </summary> | ||
118 | /// <remarks> | ||
119 | /// The object passed in is first written to an internal buffer, and | ||
120 | /// then to the output in several write operations. This means that | ||
121 | /// for many applications you will want to buffer the output. In the | ||
122 | /// case of writing to files, it could be faster to buffer the output. | ||
123 | /// In the case of writing to a socket buffering could prevent sending | ||
124 | /// many small packets. | ||
125 | /// | ||
126 | /// No flushing is done by this method, it is left to the caller to | ||
127 | /// determine the proper time to flush their streams. | ||
128 | /// </remarks> | ||
129 | /// <param name="obj">The object to be written.</param> | ||
73 | public void WriteObject( GatsObject obj ) | 130 | public void WriteObject( GatsObject obj ) |
74 | { | 131 | { |
75 | MemoryStream ms = new MemoryStream(); | 132 | MemoryStream ms = new MemoryStream(); |