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
- InfoCardRSACryptoProvider.cs
- ClientRuntimeConfig.cs
- Constants.cs
- HttpCachePolicyElement.cs
- HandleCollector.cs
- HScrollBar.cs
- CollectionChangeEventArgs.cs
- SignatureDescription.cs
- DefaultCommandConverter.cs
- Random.cs
- SortQuery.cs
- ManipulationBoundaryFeedbackEventArgs.cs
- ImmutableDispatchRuntime.cs
- CodeExpressionCollection.cs
- TraceEventCache.cs
- EditorZone.cs
- SpecularMaterial.cs
- InProcStateClientManager.cs
- SqlCacheDependency.cs
- OracleCommand.cs
- QilBinary.cs
- SimpleApplicationHost.cs
- UpdateEventArgs.cs
- ImageListStreamer.cs
- ParserExtension.cs
- WpfWebRequestHelper.cs
- StringConcat.cs
- Regex.cs
- RoutedCommand.cs
- MemberBinding.cs
- DataGridCellsPresenter.cs
- URIFormatException.cs
- DataGridRow.cs
- CommonRemoteMemoryBlock.cs
- TextEditorTyping.cs
- CustomAttributeFormatException.cs
- DataTemplate.cs
- EntityDataReader.cs
- CaretElement.cs
- SignedXmlDebugLog.cs
- ListItem.cs
- MetadataArtifactLoaderCompositeResource.cs
- BitmapSource.cs
- DataGrid.cs
- XhtmlTextWriter.cs
- Point3DValueSerializer.cs
- ResourceContainer.cs
- Shape.cs
- SiteMapHierarchicalDataSourceView.cs
- SkipStoryboardToFill.cs
- GeneralTransform2DTo3DTo2D.cs
- SendingRequestEventArgs.cs
- ProcessHostMapPath.cs
- Size3D.cs
- ResponseBodyWriter.cs
- RootBrowserWindow.cs
- ReferenceService.cs
- ScopelessEnumAttribute.cs
- PrintPreviewControl.cs
- CopyEncoder.cs
- DPCustomTypeDescriptor.cs
- UseAttributeSetsAction.cs
- InheritanceAttribute.cs
- ProxyAttribute.cs
- DetailsViewInsertEventArgs.cs
- PackagePartCollection.cs
- DateBoldEvent.cs
- OpCodes.cs
- TypeDelegator.cs
- IgnoreFlushAndCloseStream.cs
- PasswordPropertyTextAttribute.cs
- LineBreak.cs
- GeometryGroup.cs
- AppSettingsExpressionBuilder.cs
- ScopeElement.cs
- SecurityTokenValidationException.cs
- VisualBasicDesignerHelper.cs
- SerializationAttributes.cs
- AppSettingsReader.cs
- BrowserCapabilitiesFactoryBase.cs
- ExecutionContext.cs
- UInt32Storage.cs
- ModelEditingScope.cs
- VectorConverter.cs
- QilValidationVisitor.cs
- TextEditorParagraphs.cs
- RegexInterpreter.cs
- UnlockCardRequest.cs
- CategoryNameCollection.cs
- SQLDouble.cs
- AutomationProperties.cs
- DesignerView.cs
- LinearKeyFrames.cs
- Image.cs
- DesignBindingPropertyDescriptor.cs
- PropertyGeneratedEventArgs.cs
- GacUtil.cs
- DateTimeFormatInfo.cs
- Function.cs
- PixelFormats.cs