Allow schema files that are missing checksums on the !!SCHEMAMATIC line.
[versaplex.git] / wvdbus-sharp / protocol.cs
blob8b10ef44bc78614034197f8d3182aa62c60dd594
1 // Copyright 2006 Alp Toker <alp@atoker.com>
2 // This software is made available under the MIT License
3 // See COPYING for details
4 //
5 using System;
6 using System.Collections.Generic;
7 using Wv.Extensions;
9 namespace Wv
11 namespace Dbus
13 public enum MType : byte
15 Invalid = 0,
16 MethodCall = 1,
17 MethodReturn = 2,
18 Error = 3,
19 Signal = 4,
22 public enum Field : byte
24 Invalid = 0,
25 Path = 1,
26 Interface = 2,
27 Member = 3,
28 ErrorName = 4,
29 ReplySerial = 5,
30 Destination = 6,
31 Sender = 7,
32 Signature = 8,
35 public enum Endian : byte
37 Little = (byte)'l',
38 Big = (byte)'B',
41 [Flags]
42 public enum MFlag : byte
44 None = 0x00,
45 NoReplyExpected = 0x01,
46 NoAutoStart = 0x02,
49 public enum DType : byte
51 Invalid = (byte)'\0',
53 Byte = (byte)'y',
54 Boolean = (byte)'b',
55 Int16 = (byte)'n',
56 UInt16 = (byte)'q',
57 Int32 = (byte)'i',
58 UInt32 = (byte)'u',
59 Int64 = (byte)'x',
60 UInt64 = (byte)'t',
61 Single = (byte)'f',
62 Double = (byte)'d',
63 String = (byte)'s',
64 ObjectPath = (byte)'o',
65 Signature = (byte)'g',
67 Array = (byte)'a',
68 Variant = (byte)'v',
70 Struct = (byte)'r',
71 StructBegin = (byte)'(',
72 StructEnd = (byte)')',
74 DictEntry = (byte)'e',
75 DictEntryBegin = (byte)'{',
76 DictEntryEnd = (byte)'}',
79 static class Protocol
81 //protocol versions that we support
82 public const byte MinVersion = 0;
83 public const byte Version = 1;
84 public const byte MaxVersion = Version;
86 public const uint MaxMessageLength = 134217728; //2 to the 27th power
87 public const uint MaxArrayLength = 67108864; //2 to the 26th power
88 public const uint MaxSignatureLength = 255;
89 public const uint MaxArrayDepth = 32;
90 public const uint MaxStructDepth = 32;
92 public static int PadNeeded (int pos, int alignment)
94 int pad = pos % alignment;
95 pad = pad == 0 ? 0 : alignment - pad;
97 return pad;
100 public static int Padded (int pos, int alignment)
102 int pad = pos % alignment;
103 if (pad != 0)
104 pos += alignment - pad;
106 return pos;
109 public static int GetAlignment(DType dtype)
111 switch (dtype) {
112 case DType.Byte:
113 return 1;
114 case DType.Boolean:
115 return 4;
116 case DType.Int16:
117 case DType.UInt16:
118 return 2;
119 case DType.Int32:
120 case DType.UInt32:
121 return 4;
122 case DType.Int64:
123 case DType.UInt64:
124 return 8;
125 case DType.Single:
126 return 4;
127 case DType.Double:
128 return 8;
129 case DType.String:
130 return 4;
131 case DType.ObjectPath:
132 return 4;
133 case DType.Signature:
134 return 1;
135 case DType.Array:
136 return 4;
137 case DType.Struct:
138 case DType.StructBegin:
139 case DType.StructEnd:
140 case DType.DictEntry:
141 case DType.DictEntryBegin:
142 case DType.DictEntryEnd:
143 return 8;
144 case DType.Variant:
145 return 1;
146 case DType.Invalid:
147 default:
148 throw new Exception("Cannot determine alignment of " + dtype);
154 public class WvDbusError : Exception
156 public WvDbusError() : base()
160 public WvDbusError(string msg) : base(msg)
164 public WvDbusError(string msg, Exception inner) : base(msg, inner)