Class BinUtils
  
  Facilitates read.writing binary BSON primitives. Developers should not normally use this class
as it is used by serializers and socket low-level code
 
  
  
    Inheritance
    System.Object
    BinUtils
   
  
    Inherited Members
    
      System.Object.Equals(System.Object)
    
    
      System.Object.Equals(System.Object, System.Object)
    
    
      System.Object.GetHashCode()
    
    
      System.Object.GetType()
    
    
      System.Object.MemberwiseClone()
    
    
      System.Object.ReferenceEquals(System.Object, System.Object)
    
    
      System.Object.ToString()
    
   
  
  Assembly: NFX.dll
  Syntax
  
    public static class BinUtils
   
  Fields
  
  
  
  TERMINATOR
  
  
  Declaration
  
    public const byte TERMINATOR = 0
   
  Field Value
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Byte | 
         | 
      
    
  
  Properties
  
  
  
  
  UTF8Encoding
  
  
  Declaration
  
    public static UTF8Encoding UTF8Encoding { get; }
   
  Property Value
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Text.UTF8Encoding | 
         | 
      
    
  
  Methods
  
  
  
  
  GetIntDigitCount(Int32)
  Returns number of digits in 32-bit integer value
 
  
  Declaration
  
    public static short GetIntDigitCount(int value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Int32 | 
        value | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int16 | 
         | 
      
    
  
  
  
  
  ReadByte(Stream)
  
  
  Declaration
  
    public static byte ReadByte(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Byte | 
         | 
      
    
  
  
  
  
  ReadCString(Stream)
  Reads BSON cstring from stream
 
  
  Declaration
  
    public static string ReadCString(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
  
  
  ReadCString(Stream, Int32)
  Reads BSON cstring from stream
 
  
  Declaration
  
    public static string ReadCString(Stream stream, int length)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Int32 | 
        length | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
  
  
  ReadDouble(Stream)
  
  
  Declaration
  
    public static double ReadDouble(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Double | 
         | 
      
    
  
  
  
  
  ReadElementType(Stream)
  Reads BSON element type from stream
 
  
  Declaration
  
    public static BSONElementType ReadElementType(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
  
  
  
  ReadInt16(Byte[], Int32)
  Reads 16-bit int from byte array
 
  
  Declaration
  
    public static short ReadInt16(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int16 | 
         | 
      
    
  
  
  
  
  ReadInt16(Stream)
  Reads 16-bit int from stream
 
  
  Declaration
  
    public static short ReadInt16(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int16 | 
         | 
      
    
  
  
  
  
  ReadInt32(Byte[], Int32)
  Reads 32-bit int from byte array
 
  
  Declaration
  
    public static int ReadInt32(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int32 | 
         | 
      
    
  
  
  
  
  ReadInt32(Stream)
  Reads 32-bit int from stream
 
  
  Declaration
  
    public static int ReadInt32(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int32 | 
         | 
      
    
  
  
  
  
  ReadInt64(Byte[], Int32)
  Reads 64-bit int from byte array
 
  
  Declaration
  
    public static long ReadInt64(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int64 | 
         | 
      
    
  
  
  
  
  ReadInt64(Stream)
  Reads 64-bit int from stream
 
  
  Declaration
  
    public static long ReadInt64(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int64 | 
         | 
      
    
  
  
  
  
  ReadUInt16(Byte[], Int32)
  Reads unsigned 16-bit int from byte array
 
  
  Declaration
  
    public static ushort ReadUInt16(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt16 | 
         | 
      
    
  
  
  
  
  ReadUInt16(Stream)
  Reads unsigned 16-bit int from stream
 
  
  Declaration
  
    public static ushort ReadUInt16(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt16 | 
         | 
      
    
  
  
  
  
  ReadUInt24(Byte[], Int32)
  Reads 24-bit int (less than 2^24) from byte array
 
  
  Declaration
  
    public static uint ReadUInt24(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt32 | 
         | 
      
    
  
  
  
  
  ReadUInt32(Byte[], Int32)
  Reads unsigned 32-bit int from byte array
 
  
  Declaration
  
    public static uint ReadUInt32(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt32 | 
         | 
      
    
  
  
  
  
  ReadUInt32(Stream)
  Reads unsigned 32-bit int from stream
 
  
  Declaration
  
    public static uint ReadUInt32(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt32 | 
         | 
      
    
  
  
  
  
  ReadUInt64(Byte[], Int32)
  Reads unsigned 64-bit int from byte array
 
  
  Declaration
  
    public static ulong ReadUInt64(byte[] bytes, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        bytes | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt64 | 
         | 
      
    
  
  
  
  
  ReadUInt64(Stream)
  Reads unsigned 64-bit int from stream
 
  
  Declaration
  
    public static ulong ReadUInt64(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.UInt64 | 
         | 
      
    
  
  
  
  
  WriteBinary(Stream, Byte[])
  
  
  Declaration
  
    public static void WriteBinary(Stream stream, byte[] value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Byte[] | 
        value | 
         | 
      
    
  
  
  
  
  WriteByte(Stream, Byte)
  
  
  Declaration
  
    public static void WriteByte(Stream stream, byte value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Byte | 
        value | 
         | 
      
    
  
  
  
  
  WriteCString(Stream, String)
  Writes BSON cstring to stream
 
  
  Declaration
  
    public static void WriteCString(Stream stream, string value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.String | 
        value | 
         | 
      
    
  
  
  
  
  WriteCStringToBuffer(String)
  
  
  Declaration
  
    public static byte[] WriteCStringToBuffer(string value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.String | 
        value | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Byte[] | 
         | 
      
    
  
  
  
  
  WriteDouble(Stream, Double)
  
  
  Declaration
  
    public static void WriteDouble(Stream stream, double value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Double | 
        value | 
         | 
      
    
  
  
  
  
  WriteInt16(Byte[], Int16, Int32)
  Writes 16-bit int to byte array
 
  
  Declaration
  
    public static void WriteInt16(byte[] buffer, short value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.Int16 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteInt16(Stream, Int16)
  Writes 16-bit int to stream
 
  
  Declaration
  
    public static void WriteInt16(Stream stream, short value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Int16 | 
        value | 
         | 
      
    
  
  
  
  
  WriteInt32(Byte[], Int32, Int32)
  Writes 32bit int to byte array
 
  
  Declaration
  
    public static void WriteInt32(byte[] buffer, int value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.Int32 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteInt32(Stream, Int32)
  Writes 32-bit int to stream
 
  
  Declaration
  
    public static void WriteInt32(Stream stream, int value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Int32 | 
        value | 
         | 
      
    
  
  
  
  
  WriteInt64(Byte[], Int64, Int32)
  Writes 64-bit int to byte array
 
  
  Declaration
  
    public static void WriteInt64(byte[] buffer, long value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.Int64 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteInt64(Stream, Int64)
  Writes 64-bit int to stream
 
  
  Declaration
  
    public static void WriteInt64(Stream stream, long value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.Int64 | 
        value | 
         | 
      
    
  
  
  
  
  WriteTerminator(Stream)
  Writes terminator 0x00 symbol to stream
 
  
  Declaration
  
    public static void WriteTerminator(Stream stream)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
    
  
  
  
  
  WriteUInt16(Byte[], UInt16, Int32)
  Writes unsigned 16-bit int to byte array
 
  
  Declaration
  
    public static void WriteUInt16(byte[] buffer, ushort value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.UInt16 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteUInt16(Stream, UInt16)
  Writes unsigned 16-bit int to stream
 
  
  Declaration
  
    public static void WriteUInt16(Stream stream, ushort value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.UInt16 | 
        value | 
         | 
      
    
  
  
  
  
  WriteUInt24(Byte[], UInt32, Int32)
  Writes unsigned 24bit int (less than 2^24) to byte array
 
  
  Declaration
  
    public static void WriteUInt24(byte[] buffer, uint value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.UInt32 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteUInt32(Byte[], UInt32, Int32)
  Writes unsigned 32bit int to byte array
 
  
  Declaration
  
    public static void WriteUInt32(byte[] buffer, uint value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.UInt32 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteUInt32(Stream, UInt32)
  Writes unsigned 32-bit int to stream
 
  
  Declaration
  
    public static void WriteUInt32(Stream stream, uint value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.UInt32 | 
        value | 
         | 
      
    
  
  
  
  
  WriteUInt64(Byte[], UInt64, Int32)
  Writes unsigned 64-bit int to byte array
 
  
  Declaration
  
    public static void WriteUInt64(byte[] buffer, ulong value, int startIdx = 0)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Byte[] | 
        buffer | 
         | 
      
      
        | System.UInt64 | 
        value | 
         | 
      
      
        | System.Int32 | 
        startIdx | 
         | 
      
    
  
  
  
  
  WriteUInt64(Stream, UInt64)
  Writes unsigned 64-bit int to stream
 
  
  Declaration
  
    public static void WriteUInt64(Stream stream, ulong value)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.IO.Stream | 
        stream | 
         | 
      
      
        | System.UInt64 | 
        value | 
         |