Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- ComponentConverter.cs
- RequestCacheValidator.cs
- EventListenerClientSide.cs
- DrawingContext.cs
- XmlNodeChangedEventArgs.cs
- DoubleAnimationBase.cs
- ReadOnlyCollectionBase.cs
- PackageRelationshipCollection.cs
- WebPartConnectionsDisconnectVerb.cs
- ScrollEvent.cs
- ListControlBuilder.cs
- BasicBrowserDialog.designer.cs
- GenericTextProperties.cs
- WpfPayload.cs
- Substitution.cs
- CorrelationKeyCalculator.cs
- DecodeHelper.cs
- QueryContinueDragEventArgs.cs
- BuildManager.cs
- FixedSOMGroup.cs
- SendMessageRecord.cs
- State.cs
- AggregateException.cs
- HttpModuleActionCollection.cs
- SafeHandles.cs
- _UriTypeConverter.cs
- BaseParser.cs
- BuildProvidersCompiler.cs
- SecurityUtils.cs
- SelectionHighlightInfo.cs
- QueryActivatableWorkflowsCommand.cs
- UnitySerializationHolder.cs
- ClientConvert.cs
- InstanceOwnerQueryResult.cs
- TextReader.cs
- SafeFindHandle.cs
- IfElseDesigner.xaml.cs
- ManagementClass.cs
- HttpHostedTransportConfiguration.cs
- Filter.cs
- ProxyElement.cs
- ComPersistableTypeElement.cs
- NavigatorInput.cs
- MexServiceChannelBuilder.cs
- backend.cs
- PointConverter.cs
- FloaterParagraph.cs
- TreeViewCancelEvent.cs
- UnsafeNativeMethods.cs
- SafeProcessHandle.cs
- StringDictionary.cs
- XmlSchemaSequence.cs
- HttpVersion.cs
- ContextStack.cs
- PropertyItem.cs
- TextWriterTraceListener.cs
- PathTooLongException.cs
- SignedXml.cs
- DocumentEventArgs.cs
- EdgeProfileValidation.cs
- ViewManager.cs
- ComponentConverter.cs
- ParagraphResult.cs
- DocumentGrid.cs
- ResourceAttributes.cs
- JsonObjectDataContract.cs
- SqlClientPermission.cs
- ToolStripDropTargetManager.cs
- HttpRequest.cs
- BinaryFormatterWriter.cs
- ObjectDataSourceView.cs
- SystemIPAddressInformation.cs
- ListBase.cs
- _OverlappedAsyncResult.cs
- SqlFunctionAttribute.cs
- TextTreeFixupNode.cs
- ScriptingJsonSerializationSection.cs
- ErrorView.xaml.cs
- SystemNetworkInterface.cs
- ReflectionTypeLoadException.cs
- ModifiableIteratorCollection.cs
- ExceptionRoutedEventArgs.cs
- OperationPickerDialog.designer.cs
- Effect.cs
- DataSourceConverter.cs
- DesignerCategoryAttribute.cs
- DbTransaction.cs
- __ConsoleStream.cs
- DataGridViewColumn.cs
- GatewayDefinition.cs
- Bitmap.cs
- RefExpr.cs
- PolyLineSegment.cs
- UnmanagedMarshal.cs
- BackgroundWorker.cs
- OrderByBuilder.cs
- VisualBrush.cs
- followingquery.cs
- BlobPersonalizationState.cs
- WebResourceAttribute.cs