Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / MS / Internal / Ink / InkSerializedFormat / MultiByteCodec.cs / 1305600 / 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, Listoutput) { 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, Listoutput) { 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, Listoutput) { 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, Listoutput) { 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
- Models.cs
- SmiConnection.cs
- ActionItem.cs
- AttributeEmitter.cs
- Variable.cs
- InvalidOperationException.cs
- CachedCompositeFamily.cs
- HttpHandlerAction.cs
- KernelTypeValidation.cs
- SID.cs
- TdsParserSafeHandles.cs
- ButtonField.cs
- DropShadowBitmapEffect.cs
- CodeTypeDeclaration.cs
- ToolboxComponentsCreatingEventArgs.cs
- UIElementPropertyUndoUnit.cs
- CodeDOMProvider.cs
- XPathNodeList.cs
- LingerOption.cs
- ListControl.cs
- XPathPatternBuilder.cs
- CompilerLocalReference.cs
- AncestorChangedEventArgs.cs
- BinaryCommonClasses.cs
- HtmlTernaryTree.cs
- ParagraphVisual.cs
- InternalControlCollection.cs
- ScriptServiceAttribute.cs
- DataViewListener.cs
- AggregateNode.cs
- IIS7WorkerRequest.cs
- WorkflowServiceNamespace.cs
- TimeSpanSecondsConverter.cs
- AbandonedMutexException.cs
- ListViewItemEventArgs.cs
- ISessionStateStore.cs
- ConnectionManagementElementCollection.cs
- PenThreadPool.cs
- UiaCoreProviderApi.cs
- ServiceDesigner.cs
- FrameworkElementFactoryMarkupObject.cs
- XmlJsonReader.cs
- ButtonBase.cs
- MenuScrollingVisibilityConverter.cs
- XmlSchemaInclude.cs
- ModelVisual3D.cs
- MetadataException.cs
- DataBinder.cs
- ChildChangedEventArgs.cs
- ExecutionContext.cs
- EntityModelBuildProvider.cs
- ReadOnlyMetadataCollection.cs
- PreviewKeyDownEventArgs.cs
- GeometryConverter.cs
- Button.cs
- FlowDocumentPage.cs
- WhitespaceRuleLookup.cs
- ConfigXmlWhitespace.cs
- Number.cs
- SvcMapFileLoader.cs
- RepeaterDataBoundAdapter.cs
- ClientOptions.cs
- TransactionWaitAsyncResult.cs
- Binding.cs
- StylusEditingBehavior.cs
- RTTypeWrapper.cs
- ParagraphResult.cs
- _SslStream.cs
- KernelTypeValidation.cs
- XsltInput.cs
- CacheOutputQuery.cs
- FileDialogCustomPlacesCollection.cs
- BitArray.cs
- MultiTrigger.cs
- ParseChildrenAsPropertiesAttribute.cs
- TypeUtils.cs
- XmlUtf8RawTextWriter.cs
- LiteralTextContainerControlBuilder.cs
- RelatedCurrencyManager.cs
- ConfigurationElement.cs
- XmlSiteMapProvider.cs
- GrammarBuilderPhrase.cs
- SafeThreadHandle.cs
- DynamicRenderer.cs
- ListMarkerLine.cs
- AccessViolationException.cs
- Visual3D.cs
- TouchDevice.cs
- Imaging.cs
- QuestionEventArgs.cs
- SqlPersonalizationProvider.cs
- IPGlobalProperties.cs
- WindowPatternIdentifiers.cs
- SqlDataSourceWizardForm.cs
- Int32CollectionConverter.cs
- GregorianCalendar.cs
- Msmq4PoisonHandler.cs
- DataGridCaption.cs
- BasicViewGenerator.cs
- RankException.cs