Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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, 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
- LongCountAggregationOperator.cs
- XmlAttribute.cs
- WarningException.cs
- ContentFilePart.cs
- QilReplaceVisitor.cs
- DynamicValidatorEventArgs.cs
- WindowsScrollBar.cs
- translator.cs
- NativeMethods.cs
- HMACSHA1.cs
- TabControlAutomationPeer.cs
- DesignerSerializerAttribute.cs
- VirtualPath.cs
- DrawingImage.cs
- ApplicationGesture.cs
- EdmComplexPropertyAttribute.cs
- StdValidatorsAndConverters.cs
- RequestCachePolicyConverter.cs
- MergeLocalizationDirectives.cs
- WebPartConnectionCollection.cs
- ExceptionCollection.cs
- ToolStripContentPanelRenderEventArgs.cs
- WebUtil.cs
- OperationContextScope.cs
- SqlClientWrapperSmiStreamChars.cs
- RestHandlerFactory.cs
- ViewCellRelation.cs
- Input.cs
- ChildDocumentBlock.cs
- AttributeQuery.cs
- Gdiplus.cs
- SelectionEditingBehavior.cs
- TrackBarRenderer.cs
- DataGridRow.cs
- ImmutableCollection.cs
- ContractNamespaceAttribute.cs
- KeyValuePairs.cs
- HttpHandlersSection.cs
- OrderedDictionary.cs
- CharAnimationBase.cs
- StandardOleMarshalObject.cs
- FormViewPageEventArgs.cs
- ObjectListItem.cs
- DetailsViewInsertedEventArgs.cs
- DbTransaction.cs
- SafeEventLogWriteHandle.cs
- OutputScope.cs
- FormatterServices.cs
- DataServiceContext.cs
- ByeMessageCD1.cs
- DeploymentSection.cs
- DynamicVirtualDiscoSearcher.cs
- View.cs
- BitmapData.cs
- RSAPKCS1SignatureFormatter.cs
- ExeConfigurationFileMap.cs
- ButtonBaseAdapter.cs
- AttributeInfo.cs
- ConfigurationSectionGroup.cs
- MetadataHelper.cs
- ConfigXmlSignificantWhitespace.cs
- GetIndexBinder.cs
- CalendarDataBindingHandler.cs
- StdValidatorsAndConverters.cs
- RangeBaseAutomationPeer.cs
- ObjectDataSourceView.cs
- DispatcherHooks.cs
- ContentPlaceHolder.cs
- AnimationStorage.cs
- WebPartMovingEventArgs.cs
- BitmapSizeOptions.cs
- DispatchProxy.cs
- OleDbConnection.cs
- ModuleBuilderData.cs
- ProfileModule.cs
- ConfigXmlComment.cs
- PeerTransportElement.cs
- DataControlHelper.cs
- EventSinkHelperWriter.cs
- XmlReaderDelegator.cs
- DrawingContextWalker.cs
- TargetConverter.cs
- MenuItemBinding.cs
- DependencyObjectProvider.cs
- WindowsTooltip.cs
- NameValueConfigurationElement.cs
- MarkupWriter.cs
- UserControlDesigner.cs
- PenThreadWorker.cs
- ConnectionManager.cs
- InfoCardKeyedHashAlgorithm.cs
- IdleTimeoutMonitor.cs
- ResourceIDHelper.cs
- XamlSerializer.cs
- Point.cs
- VideoDrawing.cs
- ViewBase.cs
- MulticastNotSupportedException.cs
- MSAAEventDispatcher.cs
- TimeStampChecker.cs