From f51a1e16897a624278073825cdcab68e62ff7cf3 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 29 Sep 2008 17:26:37 -0400 Subject: [PATCH] One less redundant GetAlignment function. --- dbus-sharp/MessageReader.cs | 1 - dbus-sharp/Protocol.cs | 23 ++++++++++++++--------- dbus-sharp/msgiter.cs | 41 +---------------------------------------- 3 files changed, 15 insertions(+), 50 deletions(-) diff --git a/dbus-sharp/MessageReader.cs b/dbus-sharp/MessageReader.cs index 2e00874..20f3827 100644 --- a/dbus-sharp/MessageReader.cs +++ b/dbus-sharp/MessageReader.cs @@ -264,7 +264,6 @@ namespace Wv int endPos = pos + (int)ln; - //while (stream.Position != endPos) while (pos < endPos) { ReadPad(8); diff --git a/dbus-sharp/Protocol.cs b/dbus-sharp/Protocol.cs index 0dc8893..0547e7b 100644 --- a/dbus-sharp/Protocol.cs +++ b/dbus-sharp/Protocol.cs @@ -4,6 +4,7 @@ // using System; using System.Collections.Generic; +using Wv.Extensions; namespace Wv { @@ -128,7 +129,8 @@ namespace Wv public const uint MaxArrayDepth = 32; public const uint MaxStructDepth = 32; - //this is not strictly related to Protocol since names are passed around as strings + // this is not strictly related to Protocol since names are passed + // around as strings internal const uint MaxNameLength = 255; public static int PadNeeded (int pos, int alignment) @@ -148,7 +150,7 @@ namespace Wv return pos; } - public static int GetAlignment (DType dtype) + public static int GetAlignment(DType dtype) { switch (dtype) { case DType.Byte: @@ -164,7 +166,7 @@ namespace Wv case DType.Int64: case DType.UInt64: return 8; - case DType.Single: //Not yet supported! + case DType.Single: return 4; case DType.Double: return 8; @@ -177,23 +179,26 @@ namespace Wv case DType.Array: return 4; case DType.Struct: + case DType.StructBegin: + case DType.StructEnd: + case DType.DictEntry: + case DType.DictEntryBegin: + case DType.DictEntryEnd: return 8; case DType.Variant: return 1; - case DType.DictEntry: - return 8; case DType.Invalid: default: - throw new Exception ("Cannot determine alignment of " + dtype); + throw new Exception("Cannot determine alignment of " + dtype); } } - //this class may not be the best place for Verbose + // this class may not be the best place for Verbose public readonly static bool Verbose; - static Protocol () + static Protocol() { - Verbose = !String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("DBUS_VERBOSE")); + Verbose = wv.getenv("DBUS_VERBOSE").ne(); } } } diff --git a/dbus-sharp/msgiter.cs b/dbus-sharp/msgiter.cs index 0889b05..fdc24a2 100644 --- a/dbus-sharp/msgiter.cs +++ b/dbus-sharp/msgiter.cs @@ -240,45 +240,6 @@ namespace Wv } } - protected int getalign(string sig) - { - DType dtype = (DType)sig[0]; - - switch (dtype) - { - case DType.Byte: - return 1; - case DType.Boolean: - return 4; - case DType.Int16: - case DType.UInt16: - return 2; - case DType.Int32: - case DType.UInt32: - return 4; - case DType.Int64: - case DType.UInt64: - return 8; - case DType.Single: - return 4; - case DType.Double: - return 8; - case DType.String: - case DType.ObjectPath: - return 4; - case DType.Signature: - case DType.Variant: - return 1; - case DType.Array: - return 4; - case DType.StructBegin: - case DType.DictEntryBegin: - return 8; - default: - throw new Exception("Unhandled D-Bus type: " + dtype); - } - } - void pad(int align) { int pad = (align - (pos % align)) % align; @@ -404,7 +365,7 @@ namespace Wv { int len = ReadLength(); wv.print("Array length is 0x{0:x} bytes\n", len); - pad(getalign(subsig)); + pad(Protocol.GetAlignment((DType)subsig[0])); var x = new WvDBusIter_Array(conv, subsig, data, pos, pos+len); _advance(len); -- 2.11.4.GIT