Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / MS / Internal / Ink / InkSerializedFormat / MultiByteCodec.cs / 1 / MultiByteCodec.cs
using MS.Utility;
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Ink;
using System.Collections.Generic;
using MS.Internal.Ink.InkSerializedFormat;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// MultiByteCodec
///
internal class MultiByteCodec
{
///
/// MultiByteCodec
///
internal MultiByteCodec()
{
}
///
/// Encode
///
///
///
internal void Encode(uint data, List output)
{
if (output == null)
{
throw new ArgumentNullException("output");
}
while (data > 0x7f)
{
byte byteToAdd = (byte)(0x80 | (byte)data & 0x7f);
output.Add(byteToAdd);
data >>= 7;
}
byte finalByteToAdd = (byte)(data & 0x7f);
output.Add(finalByteToAdd);
}
///
/// SignEncode
///
///
///
internal void SignEncode(int data, List output)
{
uint xfData = 0;
if (data < 0)
{
xfData = (uint)( (-data << 1) | 0x01 );
}
else
{
xfData = (uint)data << 1;
}
Encode(xfData, output);
}
///
/// Decode
///
///
///
///
///
internal uint Decode(byte[] input, int inputIndex, ref uint data)
{
Debug.Assert(input != null);
Debug.Assert(inputIndex < input.Length);
// We care about first 5 bytes
uint cb = (input.Length - inputIndex > 5) ? 5 : (uint)(input.Length - inputIndex);
uint index = 0;
data = 0;
while ((index < cb) && (input[index] > 0x7f))
{
int leftShift = (int)(index * 7);
data |= (uint)((input[index] & 0x7f) << leftShift);
++index;
}
if (index < cb)
{
int leftShift = (int)(index * 7);
data |= (uint)((input[index] & 0x7f) << leftShift);
}
else
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("invalid input in MultiByteCodec.Decode"));
}
return (index + 1);
}
///
/// SignDecode
///
///
///
///
///
internal uint SignDecode(byte[] input, int inputIndex, ref int data)
{
Debug.Assert(input != null); //already validated at the AlgoModule level
if (inputIndex >= input.Length)
{
throw new ArgumentOutOfRangeException("inputIndex");
}
uint xfData = 0;
uint cb = Decode(input, inputIndex, ref xfData);
data = (0 != (0x01 & xfData)) ? -(int)(xfData >> 1) : (int)(xfData >> 1);
return cb;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using MS.Utility;
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Ink;
using System.Collections.Generic;
using MS.Internal.Ink.InkSerializedFormat;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// MultiByteCodec
///
internal class MultiByteCodec
{
///
/// MultiByteCodec
///
internal MultiByteCodec()
{
}
///
/// Encode
///
///
///
internal void Encode(uint data, List output)
{
if (output == null)
{
throw new ArgumentNullException("output");
}
while (data > 0x7f)
{
byte byteToAdd = (byte)(0x80 | (byte)data & 0x7f);
output.Add(byteToAdd);
data >>= 7;
}
byte finalByteToAdd = (byte)(data & 0x7f);
output.Add(finalByteToAdd);
}
///
/// SignEncode
///
///
///
internal void SignEncode(int data, List output)
{
uint xfData = 0;
if (data < 0)
{
xfData = (uint)( (-data << 1) | 0x01 );
}
else
{
xfData = (uint)data << 1;
}
Encode(xfData, output);
}
///
/// Decode
///
///
///
///
///
internal uint Decode(byte[] input, int inputIndex, ref uint data)
{
Debug.Assert(input != null);
Debug.Assert(inputIndex < input.Length);
// We care about first 5 bytes
uint cb = (input.Length - inputIndex > 5) ? 5 : (uint)(input.Length - inputIndex);
uint index = 0;
data = 0;
while ((index < cb) && (input[index] > 0x7f))
{
int leftShift = (int)(index * 7);
data |= (uint)((input[index] & 0x7f) << leftShift);
++index;
}
if (index < cb)
{
int leftShift = (int)(index * 7);
data |= (uint)((input[index] & 0x7f) << leftShift);
}
else
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("invalid input in MultiByteCodec.Decode"));
}
return (index + 1);
}
///
/// SignDecode
///
///
///
///
///
internal uint SignDecode(byte[] input, int inputIndex, ref int data)
{
Debug.Assert(input != null); //already validated at the AlgoModule level
if (inputIndex >= input.Length)
{
throw new ArgumentOutOfRangeException("inputIndex");
}
uint xfData = 0;
uint cb = Decode(input, inputIndex, ref xfData);
data = (0 != (0x01 & xfData)) ? -(int)(xfData >> 1) : (int)(xfData >> 1);
return cb;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GeneralTransformCollection.cs
- HostUtils.cs
- XmlSerializer.cs
- IndexedWhereQueryOperator.cs
- FormatVersion.cs
- DynamicAttribute.cs
- HTTPAPI_VERSION.cs
- MessagePartDescription.cs
- CanExecuteRoutedEventArgs.cs
- AbsoluteQuery.cs
- PhoneCallDesigner.cs
- SecurityCredentialsManager.cs
- PackageProperties.cs
- ProjectionPath.cs
- IsolatedStorageFilePermission.cs
- RequestTimeoutManager.cs
- CompressEmulationStream.cs
- AesManaged.cs
- ScriptIgnoreAttribute.cs
- AmbientProperties.cs
- ActiveXHelper.cs
- WebPartZone.cs
- InstanceKeyCompleteException.cs
- IChannel.cs
- PageThemeCodeDomTreeGenerator.cs
- HttpCacheParams.cs
- DbException.cs
- WmpBitmapDecoder.cs
- Byte.cs
- DetailsViewUpdatedEventArgs.cs
- HWStack.cs
- _HeaderInfo.cs
- VoiceInfo.cs
- SimpleHandlerFactory.cs
- MessageHeaders.cs
- DBCommandBuilder.cs
- UriParserTemplates.cs
- CSharpCodeProvider.cs
- NamedPipeChannelFactory.cs
- PopupRoot.cs
- BamlResourceContent.cs
- ClientSettingsProvider.cs
- UnsafeNativeMethods.cs
- JoinElimination.cs
- SoapReflectionImporter.cs
- TemplateColumn.cs
- SQLUtility.cs
- WorkerRequest.cs
- FileSystemEventArgs.cs
- PersonalizationStateQuery.cs
- WebPartConnectionsConnectVerb.cs
- Triplet.cs
- SoapCommonClasses.cs
- HandlerWithFactory.cs
- DefaultEventAttribute.cs
- GridViewEditEventArgs.cs
- CmsInterop.cs
- RSAPKCS1SignatureDeformatter.cs
- ControlParameter.cs
- FileDialog.cs
- ScrollableControl.cs
- MenuItem.cs
- AccessibleObject.cs
- Point.cs
- smtpconnection.cs
- NativeMethods.cs
- PreviewPrintController.cs
- ToolStripOverflow.cs
- SqlConnection.cs
- ProfileManager.cs
- FileCodeGroup.cs
- SqlStream.cs
- HatchBrush.cs
- DataObjectFieldAttribute.cs
- ConfigXmlElement.cs
- RenamedEventArgs.cs
- WebPartCollection.cs
- BrowsableAttribute.cs
- CodeGen.cs
- GPRECT.cs
- ConfigXmlDocument.cs
- UrlMapping.cs
- PartitionerStatic.cs
- EndpointDiscoveryMetadata11.cs
- SystemBrushes.cs
- x509utils.cs
- XmlTextWriter.cs
- TypeUtil.cs
- DynamicILGenerator.cs
- DataException.cs
- CodeTypeConstructor.cs
- ThreadPool.cs
- DataGridViewUtilities.cs
- BitmapEffectOutputConnector.cs
- TemplateControlCodeDomTreeGenerator.cs
- MULTI_QI.cs
- Block.cs
- OperationResponse.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- FixedPage.cs