MDUtils.cs :  » Aspect-Oriented-Frameworks » Runtime-Assembly-Instrumentation-Library » Mono » PEToolkit » Metadata » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Aspect Oriented Frameworks » Runtime Assembly Instrumentation Library 
Runtime Assembly Instrumentation Library » Mono » PEToolkit » Metadata » MDUtils.cs
/*
 * Copyright (c) 2002 Sergey Chaban <serge@wildwestsoftware.com>
 */

using System;
//using System.Runtime.InteropServices;

namespace Mono.PEToolkit.Metadata{

  public sealed class MDUtils {

    // Holds true if machine is little-endian.
    private static bool isLE;

    static MDUtils()
    {
      isLE = BitConverter.IsLittleEndian;
    }

    private MDUtils()
    {
    }


    public static int CompressData(int data, out int res)
    {
      res = data;
      int len = 4;

      if (data < 0) {
        // data is actually unsigned,
        // that's why this empty clause is needed.
      } else if (data < 0x80) {
        res = data;
        len = 1;
      } else if (data < 0x4000) {
        res = ((data >> 8) | 0x80) + ((data & 0xFF) << 8);
        len = 2;
      } else if (data < 0x1FFFFFFF) {
        res = ((data >> 24) | 0xC0)        |
              (((data >> 16) & 0xFF) << 8) |
              (((data >> 8) & 0xFF) << 16) |
              ((data & 0xFF) << 24);
        len = 4;
      }

      return len;
    }

    unsafe public static int CompressData(void* pData, void* pRes)
    {
      byte* p = (byte*) pData;

      int data = (isLE)
                 ? *(int*)p
                 : p [0] + (p [1] << 8) + (p [2] << 16) + (p [3] << 24);

      int res = 0;
      int len = CompressData(data, out res);
      p = (byte*) pRes;

      if (isLE) {
        *(int*)p = res;
      } else {
        *p++ = (byte) (res & 0xFF);
        *p++ = (byte) (res >> 8);
        *p++ = (byte) (res >> 16);
        *p++ = (byte) (res >> 24);
      }
      return len;
    }


    public static int Max(params int [] list)
    {
      int len = (list != null) ? list.Length : 0;
      if (len == 0) return 0;
      int max = list [0];
      for (int i = 1; i < len; i++) {
        if (list [i] > max) max = list [i];
      }
      return max;
    }


  }

}

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.