• Avalanche.Core
Search Results for

    Show / Hide Table of Contents
    • Avalanche.Accessor
      • Introduction
      • IAccessor
        • IAccessor
        • IFieldAccessor
        • IListAccessor
        • IMapAccessor
        • IRecordAccessor
        • IOneOfAccessor
        • IAnyAccessor
      • Dto
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
      • Articles
        • Dependency Injection
        • AccessorMessages
    • Avalanche.Binding
      • Introduction
    • Avalanche.Configuration
      • Introduction
      • Configuration Binding
      • ConfigurationExtensions
      • MemoryConfiguration
      • PrintTree
      • Saving IOptions
      • Yaml
    • Avalanche.Converter
      • Introduction
      • EnumConverter
      • Func<,>
      • HexConverter
      • PrimitiveConverter
      • StringConverter
    • Avalanche.Core
      • License
    • Avalanche.DataType
      • Introduction
      • DataType
        • IDataType
        • IListType
        • IMapType
        • IRecordType
        • IFieldType
        • IOneOfType
        • IAnyType
        • IStringType
        • IValueType
        • IIntegerType
        • IEnumerationType
        • IFloatingPointType
      • Dto
        • Introduction
        • IList<T>
        • IDictionary<K,V>
        • FieldInfo
        • Enum
        • OneOfAttribute
        • StructLayoutAttribute
        • Class
        • DtoTarget(IDataType)
        • IntermediateTarget
      • Articles
        • DataTypeRequest
        • PrintTree
        • DataTypeMessages
    • Avalanche.Emit
      • Introduction
      • TypeBuilder
      • ConstructorBuilder
      • MethodBuilder
      • PropertyBuilder
      • FieldBuilder
      • Emit
      • Utilities
        • CustomAttributeUtilities
        • ToStringRequest
    • Avalanche.FileSystem
      • Introduction
      • Abstractions
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpenStream
        • IFileSystemOpenMemory
        • IEvent
        • IEntry
        • IOption
        • IToken
      • FileSystem
      • VirtualFileSystem
      • MemoryFileSystem
      • EmbeddedFileSystem
      • HttpFileSystem
      • Decoration
      • IFileProvider
      • Utilities
        • Dispose
        • FileDictionary
        • FileScanner
        • FilterEnumerable
        • OperationSession
        • PollingFilterWatchToken
        • VisitTree
      • Article
        • Examples
        • PrintTree
    • Avalanche.Identity
      • Introduction
      • Identity
      • IdentityParts
      • IdentityInterner
      • IdentityComparer
      • Print Tree
      • IdentityAccessors
        • Introduction
        • TypeName
    • Avalanche.Localization
      • Introduction
      • Localization
      • LocalizationFile
      • LocalizationFiles
      • LocalizationFileSystem
      • LocalizationFileFormat
      • LocalizationLine
      • LocalizationLines
      • TemplateFormat
      • CultureProvider
      • FallbackCultureProvider
      • ResourceManager
      • LocalizationError
      • Microsoft.Extensions
        • Introduction
        • DependencyInjection
        • FileProvider
        • Logging
        • ITextLocalizer
        • IFileLocalizer
        • Localization
      • Asp.Net
        • Introduction
        • Supplying localization
        • Inject to pages
        • Culture Assigned
        • Minimalistic Api
        • Diagnostics
      • Pluralization
        • Introduction
        • Multiple plural parameters
        • Custom PluralRules
        • Invariant Culture
        • Unit Prefix
        • IPluralRule
        • IPluralNumber
        • IPluralRules
        • CLDRs
        • Unicode.CLDR40
        • Unicode.CLDR41
        • Unicode.CLDR42
        • Unicode.CLDR43
      • Articles
        • Alphabet localization
        • Benchmarks
        • Caching
        • Class Library
        • Demo
        • Diagnostics
        • Embedded resources
        • Emplacement
        • File localization
        • Text localization
        • Printing templates
    • Avalanche.Memory
      • Introduction
      • IMemory<T>
      • BlockMemory<T>
      • FileMemory
      • ListMemory<L, T>
      • MemoryMemory<T>
      • MMFMemory<T>
      • PointerMemory<T>
      • Slice<M, T>
      • StreamMemory
      • Concurrency
        • RWLockedMemory
        • SynchronizedMemory
      • Serialization
        • Benchmarks
        • Fixed<T>
        • Variable<T>
        • ZigZag<T>
        • StringEncoding
      • Articles
        • Fixed-size and Variable-sized
        • IBlockPool<T>
        • Print Tree
        • Read and Write events
        • Stream View
        • Zero Heap
    • Avalanche.Message
      • Introduction
      • IMessage
      • IMessageProvider
      • IMessageDescription
      • IMessageDescriptions
      • MessageDescriptionsBase
      • MessageLevel
      • Message printing
      • Messages and Exceptions
      • Microsoft.Extensions
        • DependencyInjection
      • Articles
        • Aggregate Messages
        • Localization
        • Localization Templates
        • Logging
        • Validation
    • Avalanche.Module
      • Introduction
      • IServiceCollection
      • IServiceBuilder
      • IHostBuilder
      • Dependencies
    • Avalanche.Options
      • Introduction
      • OptionsExtensions
      • OptionsMonitorCast
    • Avalanche.Protobuf
      • Introduction
    • Avalanche.Service
      • Introduction
      • Service
        • Introduction
        • IService
        • IServiceDisposable
        • IServiceDecoration
        • IServiceCast
        • IServiceObservable
        • IServiceContainer
        • Construction
        • Query
        • CancellationToken
        • CachePolicy
        • Scope
      • Handler
        • Introduction
        • IHandler
        • IHandlerCast
        • IHandlerDecoration
        • IHandlerWithOrder
        • CancellationToken
        • Cyclicity
        • Delegates
        • Invokable
        • ExportAttribute
        • OrderAttribute
        • PrintTree
        • Recursion
      • Query
        • Introduction
        • IQuery
        • IQueryCast
        • IQueryDecoration
      • Entry
        • Introduction
        • IEntry
        • IEntryCast
        • IEntryDecoration
        • IEntryObservable
        • IEntryVisitable
        • EntryState
      • Request
        • Introduction
        • IRequest
        • IRequestFor
        • IRequestToBeCached
        • IRequestToBeDisposed
        • RequestAttribute
        • ContextParameterAttribute
        • Print Tree
      • Dependency Injection
        • Introduction
        • Asp.Net
        • ServiceRequest<T>
        • Decorating a service
        • Handler
        • CachePolicy
        • CancellationToken
        • QueryLogger
        • IHostBuilder
      • Examples
        • NodeCount
        • Expression
        • Mapper
      • Articles
        • Benchmarks
        • Error Handling
        • ServiceMessages
    • Avalanche.StatusCode
      • Introduction
      • HResult
        • Introduction
        • HResult.Facilities
        • BasicMessages
        • RpcMessages
        • DispatchMessages
        • StorageMessages
        • ItfMessages
        • Win32Messages
        • WindowsMessages
        • SspiMessages
        • CertMessages
        • MediaServerMessages
        • SetupApiMessages
        • ScardMessages
        • ComPlusMessages
        • ClrMessages
        • UserModeFilterManagerMessages
        • GraphicsMessages
        • TpmServicesMessages
        • TpmSoftwareMessages
        • PlaMessages
        • FveMessages
        • FwpMessages
        • NdisMessages
        • DltMessages
      • System
        • Introduction
        • AccessControlMessages
        • AggregateMessages
        • AppDomainMessages
        • ArgumentMessages
        • ArgumentNullMessages
        • ArgumentOutOfRangeMessages
        • ArithmeticMessages
        • ArrayMessages
        • AssemblyMessages
        • BadImageFormatMessages
        • CodeContractMessages
        • CodePageMessages
        • CollectionsMessages
        • CompilerServiceMessages
        • CryptographyMessages
        • CultureMessages
        • DiagnosticsMessages
        • EventSourceMessages
        • ExecutionEngineMessages
        • FormatMessages
        • HostProtectionMessages
        • IOMessages
        • IndexOutOfRangeMessages
        • InteropServiceMessages
        • InvalidCastMessages
        • InvalidOperationMessages
        • IsolatedStorageMessages
        • LazyMessages
        • MarshalerMessages
        • MemoryMessages
        • MiscellaneousMessages
        • NotImplementedMessages
        • NotSupportedMessages
        • ObjectDisposedMessages
        • OperationCanceledMessages
        • OverflowMessages
        • PlatformMessages
        • PolicyMessages
        • PrincipalMessages
        • ProgramMessages
        • ReferenceMessages
        • ReflectionMessages
        • RegionMessages
        • RemotingMessages
        • ResourcesMessages
        • SecurityMessages
        • SerializationMessages
        • StackMessages
        • TaskMessages
        • TextMessages
        • ThreadingMessages
        • TimeZoneMessages
        • TypeMessages
        • XmlMessages
      • HttpStatusCode
      • OpcUaStatusCode
    • Avalanche.Template
      • Introduction
      • TemplateFormats
      • ITemplatePrintable
      • ITemplateFormatPrintable
      • ITemplateText
      • ITemplateBreakdown
      • ITemplateFormat
      • ITemplateFormats
      • Extract Arguments
      • Emplacement
    • Avalanche.Tokenizer
      • Introduction
      • IToken
      • ITokenizer
      • Tokenizers
    • Avalanche.Utilities
      • Introduction
      • Collections
        • ArrayList
        • ArrayUtilities
        • BijectionMap
        • CachedSelect
        • DictionaryAdapter
        • EnumerableExtensions
        • LocakableDictionary
        • LockableList
        • MapList
        • Pipe
        • RingQueue
        • StructList
        • Tuples
        • TupleUtilities
      • Comparers
        • IGraphComparer
        • IGraphComparable
        • AlphaNumericComparer
        • EnumerableComparer
        • EnumerableGraphComparer
        • ReferenceComparer
        • KeyValuePairComparer
        • DefaultComparerProvider
        • RecordComparer
      • Cloners
        • ICloner
        • IGraphCloner
        • IGraphCloneable
        • ListCloner
        • DictionaryCloner
        • FieldCloner
        • PassthroughCloner
        • RecordCloner
        • ClonerProvider
      • Dispose
        • IDisposeAttachable
        • IDisposeBelatable
      • Provider
        • Introduction
        • ProviderBase
        • Delegate
        • Pipe
        • Cache
        • ResultCapture
        • AsReadOnly
        • SharedResource
        • AsService
        • IProviderEvent
      • Record
        • IRecordDescription
        • IFieldDescription
        • IConstructorDescription
        • IConstructionDescription
        • IParameterDescription
        • IRecordProviders
        • RecordDelegates
          • RecordCreate
          • RecordClone
          • RecordCopy
          • IRecordDelegates
        • FieldDelegates
          • FieldRead
          • FieldWrite
          • RecreateWith
          • IFieldDelegates
      • Reflection
        • EnumDescription
      • String
        • IEscaper
        • UnicodeString
        • Hex
      • Miscellaneous
        • IIdGenerator
        • Permutation
        • IReadOnly
        • IUserDataContainer
        • ITreeNode
        • Void
    • Avalanche.Writer
      • Introduction
      • ConstantWriter
      • Context
      • ConvertWriter
      • DefaultConstructor
      • DelegateWriter
      • PassthroughWriter
      • Referer
      • TypeCast
      • Writer
      • WriterPipe
      • WriterMessages

    ZigZag<T>

    ZigZag<T> encodes value-types T using variable-sized encoding combined with zig-zag interleaving of positive and negative values. Encoding uses 7 bits for payload and every 8th bit describes whether 'value' continues into next octet.

    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray( 0)));           // 00
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-1)));           // 01
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+1)));           // 02
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-2)));           // 03
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+2)));           // 04
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-3)));           // 05
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+3)));           // 06
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(int.MinValue))); // FFFFFFFF0F
    WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(int.MaxValue))); // FEFFFFFF0F
    

    ZigZag<T>.Write(memory, value, bytesWritten, atIndex?) writes value-typed T to 'memory'.

    byte[] data = new byte[8];
    var memory = new ListMemory<byte[], byte>(data);
    ZigZag<ulong>.Write(memory, value: 0x100UL, out int bytesWritten);
    WriteLine(bytesWritten);        // 2
    

    ZigZag<T>.TryWrite(memory, value, bytesWritten, atIndex?) tries to write 'value' to 'memory'.

    byte[] data = new byte[8];
    var memory = new ListMemory<byte[], byte>(data);
    bool ok = ZigZag<ulong>.TryWrite(memory, value: 0x100UL, out int bytesWritten);
    WriteLine(bytesWritten);        // 2
    

    ZigZag<T>.Read(memory, bytesRead, atIndex?) reads value-typed T from 'memory'.

    byte[] data = new byte[] { 128, 2, 0, 0, 0, 0, 0, 0 };
    var memory = new ListMemory<byte[], byte>(data);
    ulong value = ZigZag<ulong>.Read(memory, out int bytesRead);
    WriteLine(value);               // 256
    WriteLine(bytesRead);           // 2
    

    ZigZag<T>.TryRead(memory, value, bytesRead, atIndex?) tries to read value-typed T from 'memory'.

    byte[] data = new byte[] { 128, 2, 0, 0, 0, 0, 0, 0 };
    var memory = new ListMemory<byte[], byte>(data);
    bool ok = ZigZag<ulong>.TryRead(memory, out ulong value, out int bytesRead);
    WriteLine(value);               // 256
    WriteLine(bytesRead);           // 2
    

    ZigZag<T>.Insert(memory, value, bytesWritten, atIndex?) inserts value-typed T to 'memory'.

    byte[] data = new byte[8];
    var memory = new Slice<ListMemory<byte[], byte>, byte>(new ListMemory<byte[], byte>(data), 0, 0, data.Length);
    ZigZag<ulong>.Insert(ref memory, value: 0x100UL, out int bytesWritten);
    WriteLine(bytesWritten);        // 2
    

    ZigZag<T>.TryInsert(memory, value, bytesWritten, atIndex?) tries to insert 'value' to 'memory'.

    byte[] data = new byte[8];
    var memory = new Slice<ListMemory<byte[], byte>, byte>(new ListMemory<byte[], byte>(data), 0, 0, data.Length);
    ZigZag<ulong>.TryInsert(ref memory, value: 0x100UL, out int bytesWritten);
    WriteLine(bytesWritten);        // 2
    

    Any value-type T can be read and written.

    var memory = new BlockMemory<byte>();
    ZigZag<DateTime>.TryInsert(ref memory, DateTime.UtcNow, out int bytesWritten);
    ZigZag<Guid>.TryInsert(ref memory, Guid.NewGuid(), out bytesWritten, atIndex: memory.Count);
    ZigZag<UInt128>.TryInsert(ref memory, new UInt128(0, 0), out bytesWritten, atIndex: memory.Count);
    

    ZigZag<T>.FixedSize returns the fixed number of bytes of unencoded value-type T.

    WriteLine(ZigZag<bool>.FixedSize);            // 1
    WriteLine(ZigZag<Byte>.FixedSize);            // 1
    WriteLine(ZigZag<SByte>.FixedSize);           // 1
    WriteLine(ZigZag<UInt16>.FixedSize);          // 1
    WriteLine(ZigZag<Int16>.FixedSize);           // 2
    WriteLine(ZigZag<Int32>.FixedSize);           // 4
    WriteLine(ZigZag<UInt32>.FixedSize);          // 4
    WriteLine(ZigZag<Int64>.FixedSize);           // 8
    WriteLine(ZigZag<UInt64>.FixedSize);          // 8
    WriteLine(ZigZag<Int128>.FixedSize);          // 16
    WriteLine(ZigZag<UInt128>.FixedSize);         // 16
    WriteLine(ZigZag<Guid>.FixedSize);            // 16
    WriteLine(ZigZag<DateTime>.FixedSize);        // 8
    WriteLine(ZigZag<DateTimeOffset>.FixedSize);  // 16
    

    ZigZag<T>.MaxEncodedSize returns the maximum number of bytes that may be needed for encoding T.

    WriteLine(ZigZag<bool>.MaxEncodedSize);            // 1
    WriteLine(ZigZag<SByte>.MaxEncodedSize);           // 2
    WriteLine(ZigZag<Byte>.MaxEncodedSize);            // 2
    WriteLine(ZigZag<Int16>.MaxEncodedSize);           // 3
    WriteLine(ZigZag<UInt16>.MaxEncodedSize);          // 3
    WriteLine(ZigZag<Int32>.MaxEncodedSize);           // 5
    WriteLine(ZigZag<UInt32>.MaxEncodedSize);          // 5
    WriteLine(ZigZag<Int64>.MaxEncodedSize);           // 10
    WriteLine(ZigZag<UInt64>.MaxEncodedSize);          // 10
    WriteLine(ZigZag<Int128>.MaxEncodedSize);          // 19
    WriteLine(ZigZag<UInt128>.MaxEncodedSize);         // 19
    WriteLine(ZigZag<Guid>.MaxEncodedSize);            // 19
    WriteLine(ZigZag<DateTime>.MaxEncodedSize);        // 10
    WriteLine(ZigZag<DateTimeOffset>.MaxEncodedSize);  // 19
    

    ZigZag<T>.EncodedSize(value) returns the exact number of bytes that are needed to encode 'value'.

    WriteLine(ZigZag<Int64>.EncodedSize( 0));                 // 1
    WriteLine(ZigZag<Int64>.EncodedSize(+1));                 // 1
    WriteLine(ZigZag<Int64>.EncodedSize(-1));                 // 1
    WriteLine(ZigZag<Int64>.EncodedSize(+127));               // 1
    WriteLine(ZigZag<Int64>.EncodedSize(-127));               // 1
    WriteLine(ZigZag<Int64>.EncodedSize(+128));               // 2
    WriteLine(ZigZag<Int64>.EncodedSize(-128));               // 2
    WriteLine(ZigZag<Int64>.EncodedSize(+16383));             // 3
    WriteLine(ZigZag<Int64>.EncodedSize(-16383));             // 3
    WriteLine(ZigZag<Int64>.EncodedSize(+16384));             // 4
    WriteLine(ZigZag<Int64>.EncodedSize(-16384));             // 4
    WriteLine(ZigZag<Int64>.EncodedSize(Int64.MinValue));     // 10
    WriteLine(ZigZag<Int64>.EncodedSize(Int64.MaxValue));     // 10
    

    ZigZag<T>.IsZigZagRecommended determines whether it is recommended to use zig-zag encoding for T. Zig-zag is recommended for signed integers.

    WriteLine(ZigZag<bool>.IsZigZagRecommended);            // False
    WriteLine(ZigZag<SByte>.IsZigZagRecommended);           // True
    WriteLine(ZigZag<Byte>.IsZigZagRecommended);            // False
    WriteLine(ZigZag<Int16>.IsZigZagRecommended);           // True
    WriteLine(ZigZag<UInt16>.IsZigZagRecommended);          // False
    WriteLine(ZigZag<Int32>.IsZigZagRecommended);           // True
    WriteLine(ZigZag<UInt32>.IsZigZagRecommended);          // False
    WriteLine(ZigZag<Int64>.IsZigZagRecommended);           // True
    WriteLine(ZigZag<UInt64>.IsZigZagRecommended);          // False
    WriteLine(ZigZag<Int128>.IsZigZagRecommended);          // True
    WriteLine(ZigZag<UInt128>.IsZigZagRecommended);         // False
    

    Full Example

    Full example
    using Avalanche.Memory;
    using Avalanche.Utilities;
    using static System.Console;
    
    public class zigzag
    {
        public static void Run()
        {
            {
                // <00>
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray( 0)));           // 00
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-1)));           // 01
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+1)));           // 02
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-2)));           // 03
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+2)));           // 04
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(-3)));           // 05
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(+3)));           // 06
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(int.MinValue))); // FFFFFFFF0F
                WriteLine(Hex.PrintFromBytes(ZigZag<int>.ToArray(int.MaxValue))); // FEFFFFFF0F
                // </00>
            }
            {
                // <01>
                byte[] data = new byte[8];
                var memory = new ListMemory<byte[], byte>(data);
                ZigZag<ulong>.Write(memory, value: 0x100UL, out int bytesWritten);
                WriteLine(bytesWritten);        // 2
                // </01>
            }
            {
                // <02>
                byte[] data = new byte[8];
                var memory = new ListMemory<byte[], byte>(data);
                bool ok = ZigZag<ulong>.TryWrite(memory, value: 0x100UL, out int bytesWritten);
                WriteLine(bytesWritten);        // 2
                // </02>
            }
            {
                // <03>
                byte[] data = new byte[] { 128, 2, 0, 0, 0, 0, 0, 0 };
                var memory = new ListMemory<byte[], byte>(data);
                ulong value = ZigZag<ulong>.Read(memory, out int bytesRead);
                WriteLine(value);               // 256
                WriteLine(bytesRead);           // 2
                // </03>
            }
            {
                // <04>
                byte[] data = new byte[] { 128, 2, 0, 0, 0, 0, 0, 0 };
                var memory = new ListMemory<byte[], byte>(data);
                bool ok = ZigZag<ulong>.TryRead(memory, out ulong value, out int bytesRead);
                WriteLine(value);               // 256
                WriteLine(bytesRead);           // 2
                // </04>
            }
            {
                // <05>
                byte[] data = new byte[8];
                var memory = new Slice<ListMemory<byte[], byte>, byte>(new ListMemory<byte[], byte>(data), 0, 0, data.Length);
                ZigZag<ulong>.Insert(ref memory, value: 0x100UL, out int bytesWritten);
                WriteLine(bytesWritten);        // 2
                // </05>
            }
            {
                // <06>
                byte[] data = new byte[8];
                var memory = new Slice<ListMemory<byte[], byte>, byte>(new ListMemory<byte[], byte>(data), 0, 0, data.Length);
                ZigZag<ulong>.TryInsert(ref memory, value: 0x100UL, out int bytesWritten);
                WriteLine(bytesWritten);        // 2
                // </06>
            }
            {
                // <11>
                var memory = new BlockMemory<byte>();
                ZigZag<DateTime>.TryInsert(ref memory, DateTime.UtcNow, out int bytesWritten);
                ZigZag<Guid>.TryInsert(ref memory, Guid.NewGuid(), out bytesWritten, atIndex: memory.Count);
                ZigZag<UInt128>.TryInsert(ref memory, new UInt128(0, 0), out bytesWritten, atIndex: memory.Count);
                // </11>
            }
            {
                // <21>
                WriteLine(ZigZag<bool>.FixedSize);            // 1
                WriteLine(ZigZag<Byte>.FixedSize);            // 1
                WriteLine(ZigZag<SByte>.FixedSize);           // 1
                WriteLine(ZigZag<UInt16>.FixedSize);          // 1
                WriteLine(ZigZag<Int16>.FixedSize);           // 2
                WriteLine(ZigZag<Int32>.FixedSize);           // 4
                WriteLine(ZigZag<UInt32>.FixedSize);          // 4
                WriteLine(ZigZag<Int64>.FixedSize);           // 8
                WriteLine(ZigZag<UInt64>.FixedSize);          // 8
                WriteLine(ZigZag<Int128>.FixedSize);          // 16
                WriteLine(ZigZag<UInt128>.FixedSize);         // 16
                WriteLine(ZigZag<Guid>.FixedSize);            // 16
                WriteLine(ZigZag<DateTime>.FixedSize);        // 8
                WriteLine(ZigZag<DateTimeOffset>.FixedSize);  // 16
                // </21>
            }        
            {
                // <22>
                WriteLine(ZigZag<bool>.MaxEncodedSize);            // 1
                WriteLine(ZigZag<SByte>.MaxEncodedSize);           // 2
                WriteLine(ZigZag<Byte>.MaxEncodedSize);            // 2
                WriteLine(ZigZag<Int16>.MaxEncodedSize);           // 3
                WriteLine(ZigZag<UInt16>.MaxEncodedSize);          // 3
                WriteLine(ZigZag<Int32>.MaxEncodedSize);           // 5
                WriteLine(ZigZag<UInt32>.MaxEncodedSize);          // 5
                WriteLine(ZigZag<Int64>.MaxEncodedSize);           // 10
                WriteLine(ZigZag<UInt64>.MaxEncodedSize);          // 10
                WriteLine(ZigZag<Int128>.MaxEncodedSize);          // 19
                WriteLine(ZigZag<UInt128>.MaxEncodedSize);         // 19
                WriteLine(ZigZag<Guid>.MaxEncodedSize);            // 19
                WriteLine(ZigZag<DateTime>.MaxEncodedSize);        // 10
                WriteLine(ZigZag<DateTimeOffset>.MaxEncodedSize);  // 19
                // </22>
            }
            {
                // <23>
                WriteLine(ZigZag<Int64>.EncodedSize( 0));                 // 1
                WriteLine(ZigZag<Int64>.EncodedSize(+1));                 // 1
                WriteLine(ZigZag<Int64>.EncodedSize(-1));                 // 1
                WriteLine(ZigZag<Int64>.EncodedSize(+127));               // 1
                WriteLine(ZigZag<Int64>.EncodedSize(-127));               // 1
                WriteLine(ZigZag<Int64>.EncodedSize(+128));               // 2
                WriteLine(ZigZag<Int64>.EncodedSize(-128));               // 2
                WriteLine(ZigZag<Int64>.EncodedSize(+16383));             // 3
                WriteLine(ZigZag<Int64>.EncodedSize(-16383));             // 3
                WriteLine(ZigZag<Int64>.EncodedSize(+16384));             // 4
                WriteLine(ZigZag<Int64>.EncodedSize(-16384));             // 4
                WriteLine(ZigZag<Int64>.EncodedSize(Int64.MinValue));     // 10
                WriteLine(ZigZag<Int64>.EncodedSize(Int64.MaxValue));     // 10
                // </23>
            }
            {
                // <31>
                WriteLine(ZigZag<bool>.IsZigZagRecommended);            // False
                WriteLine(ZigZag<SByte>.IsZigZagRecommended);           // True
                WriteLine(ZigZag<Byte>.IsZigZagRecommended);            // False
                WriteLine(ZigZag<Int16>.IsZigZagRecommended);           // True
                WriteLine(ZigZag<UInt16>.IsZigZagRecommended);          // False
                WriteLine(ZigZag<Int32>.IsZigZagRecommended);           // True
                WriteLine(ZigZag<UInt32>.IsZigZagRecommended);          // False
                WriteLine(ZigZag<Int64>.IsZigZagRecommended);           // True
                WriteLine(ZigZag<UInt64>.IsZigZagRecommended);          // False
                WriteLine(ZigZag<Int128>.IsZigZagRecommended);          // True
                WriteLine(ZigZag<UInt128>.IsZigZagRecommended);         // False
                // </31>
            }
        }
    }
    
    
    In This Article
    Back to top