public void ToBinary_WhenNumberEquals255_Returns11111111()
        {
            var convert = new BinaryConverter();
            string result = convert.ToBinary(255);

            Assert.AreEqual("11111111", result);
        }
        public void ToBinary_WhenNumberEquals1_Returns0001()
        {
            var convert = new BinaryConverter();
            string result = convert.ToBinary(1);

            Assert.AreEqual("0001", result);
        }
Example #3
0
 public RPCSocketClient()  {
     Converter = new BinaryConverter();
     Converter.FunctionCall += (fn,arg) => {
         lock(qwe2)
         Send(new RPCCallBackMessage() { arg=arg,fn=fn  });
     };
 }
 public void ConvertOne()
 {
     BinaryValidator binaryValidator = new BinaryValidator();
     BinaryConverter binaryConverter = new BinaryConverter(binaryValidator);
     int convertedValue = binaryConverter.ConvertToDecimalNumber("1");
     Assert.That(convertedValue == 1);
 }
        public void ToBinary_WhenNumberEquals126_Returns01111110()
        {
            var convert = new BinaryConverter();
            string result = convert.ToBinary(126);

            Assert.AreEqual("01111110", result);
        }
 public void ConvertNumberShouldSucceed(string binaryNumber, int result)
 {
     BinaryValidator binaryValidator = new BinaryValidator();
     BinaryConverter binaryConverter = new BinaryConverter(binaryValidator);
     int convertedValue = binaryConverter.ConvertToDecimalNumber(binaryNumber);
     Assert.That(convertedValue == result);
 }
 public void ThrowsArgumentExceptionWhenParameterIsNotBinaryNumber()
 {
     IBinaryValidator binaryValidator = new BinaryValidatorAlwaysInvalid();
     BinaryConverter binaryConverter = new BinaryConverter(binaryValidator);
     Assert.Throws<ArgumentException>(
         () => binaryConverter.ConvertToDecimalNumber("a")
         );
 }
 public void AppendBytes(byte[] value, bool recordCount, BinaryConverter converter)
 {
     if (recordCount)
     {
         AppendInt32(value.Length, converter);
     }
     stream.Write(value, 0, value.Length);
 }
 public void AppendBytes(byte[] value, int offset, int count, bool recordCount, BinaryConverter converter)
 {
     if (recordCount)
     {
         AppendInt32(count, converter);
     }
     stream.Write(value, offset, count);
 }
Example #10
0
 public static string ReadAutoString(Stream stream, BinaryConverter converter, System.Text.Encoding encoding)
 {
     int count = ReadInt32(stream, converter);
     if (count > 0)
         return ReadString(stream, count, converter, encoding);
     else
         return null;
 }
Example #11
0
 public void AppendBytes(byte[] value, bool recordCount, BinaryConverter converter)
 {
     if (recordCount)
     {
         AppendInt32(value.Length, converter);
     }
     byteArrayList.Add(value);
     length += value.Length;
 }
        public void CanSerialize_Short()
        {
            short value = short.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            short deserializedValue = converter.Deserialize<short>(bytes);

            Assert.Equal(value, deserializedValue);
        }
        public void CanSerialize_SByte()
        {
            sbyte value = sbyte.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            sbyte deserializedValue = converter.Deserialize<sbyte>(bytes);

            Assert.Equal(value, deserializedValue);
        }
        public void CanSerialize_Char()
        {
            char value = char.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            char deserializedValue = converter.Deserialize<char>(bytes);

            Assert.Equal(value, deserializedValue);
        }
 public ResultReadDataNode(int count, BinaryConverter converter, Encoding encoding, 
     ReadCompletedEventHandler Completed, ReadErrorEventHandler Error,
     ReadCompletedEventHandler resultCompleted, ReadErrorEventHandler resultError,
     object state)
     : base(new byte[count], 0, count, Completed, Error, state)
 {
     this.ConvertSetting = new ConvertSetting(converter, encoding);
     this.ResultCompleted = resultCompleted;
     this.ResultError = resultError;
 }
        public void CanSerialize_Byte()
        {
            var value = byte.MinValue;;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            var deserializedValue = converter.Deserialize<byte>(bytes);

            Assert.Equal(value, deserializedValue);
        }
        public void CanSerialize_UInt()
        {
            uint value = uint.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            uint deserializedValue = converter.Deserialize<uint>(bytes);

            Assert.Equal(value, deserializedValue);
        }
        public void ThrowsArgumentExceptionWhenParameterIsNotBinaryNumberVersionWithRhinoMocks()
        {
            IBinaryValidator binaryValidator = MockRepository.GenerateStub<IBinaryValidator>();
            binaryValidator.Stub(x => x.IsValidBinaryNumber(Arg<string>.Is.Anything))
                .Return(false);

            BinaryConverter binaryConverter = new BinaryConverter(binaryValidator);
            Assert.Throws<ArgumentException>(
                () => binaryConverter.ConvertToDecimalNumber("a")
                );
        }
Example #19
0
 public void AppendBytes(byte[] value, int offset, int count, bool recordCount, BinaryConverter converter)
 {
     if (recordCount)
     {
         AppendInt32(count, converter);
     }
     byte[] bytes = new byte[count];
     Buffer.BlockCopy(value, offset, bytes, 0, count);
     byteArrayList.Add(bytes);
     length += bytes.Length;
 }
        public void CanSerialize_Double()
        {
            double value = double.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            double deserializedValue = converter.Deserialize<double>(bytes);

            Assert.Equal(value, deserializedValue);
        }
 public void TestSetup()
 {
     Converter       = new BinaryConverter();
     singleTtlString = File.ReadAllText("data/2594007XIACKNMUAW223.ttl");
 }
        public void CanSerialize_Float()
        {
            float value = float.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            float deserializedValue = converter.Deserialize<float>(bytes);

            Assert.Equal(value, deserializedValue);
        }
Example #23
0
        /// <summary>
        /// Decompress the data.
        /// </summary>
        /// <param name="compressed">The compressed data.</param>
        /// <returns>The decompressed data.</returns>
        public byte[] Decompress(byte[] compressed)
        {
            var bits = BinaryConverter.ToBits(compressed);

            return(_tree.GetBytes(bits));
        }
        public unsafe IList <ArraySegment <byte> > CreateBuffer(IList <ArraySegment <byte> > appendTo)
        {
            // key size
            byte[] keyData   = BinaryConverter.EncodeKey(this.Key);
            int    keyLength = keyData == null ? 0 : keyData.Length;

            if (keyLength > 0xffff)
            {
                throw new InvalidOperationException("KeyTooLong");
            }

            // total payload size
            int totalLength = keyLength + 4;

            //build the header
            byte[] header = new byte[24];

            fixed(byte *buffer = header)
            {
                buffer[0x00] = 0x80;                 // magic
                buffer[0x01] = (byte)CouchbaseOpCode.Observe;

                // key length always 0x00 for observe
                buffer[0x02] = 0x00;
                buffer[0x03] = 0x00;

                // extra length
                buffer[0x04] = 0x00;

                // 5 -- data type, 0 (RAW)
                // 6,7 -- reserved, always 0

                buffer[0x06] = 0x00;
                buffer[0x07] = 0x00;

                // body length
                buffer[0x08] = (byte)(totalLength >> 24);
                buffer[0x09] = (byte)(totalLength >> 16);
                buffer[0x0a] = (byte)(totalLength >> 8);
                buffer[0x0b] = (byte)(totalLength & 255);

                buffer[0x0c] = (byte)(this.CorrelationId >> 24);
                buffer[0x0d] = (byte)(this.CorrelationId >> 16);
                buffer[0x0e] = (byte)(this.CorrelationId >> 8);
                buffer[0x0f] = (byte)(this.CorrelationId & 255);

                ulong cas = this.Cas;

                // CAS
                if (cas > 0)
                {
                    // skip this if no cas is specfied
                    buffer[0x10] = (byte)(cas >> 56);
                    buffer[0x11] = (byte)(cas >> 48);
                    buffer[0x12] = (byte)(cas >> 40);
                    buffer[0x13] = (byte)(cas >> 32);
                    buffer[0x14] = (byte)(cas >> 24);
                    buffer[0x15] = (byte)(cas >> 16);
                    buffer[0x16] = (byte)(cas >> 8);
                    buffer[0x17] = (byte)(cas & 255);
                }
            }

            var retval = appendTo ?? new List <ArraySegment <byte> >(4);

            retval.Add(new ArraySegment <byte>(header));

            var vBucketBytes = new byte[]
            {
                (byte)(VBucket >> 8), (byte)(VBucket & 255)
            };

            retval.Add(new ArraySegment <byte>(vBucketBytes));

            var keyLengthBytes = new byte[]
            {
                (byte)(keyLength >> 8), (byte)(keyLength & 255)
            };

            retval.Add(new ArraySegment <byte>(keyLengthBytes));

            retval.Add(new ArraySegment <byte>(keyData));

            return(retval);
        }
        public void CanSerialize_String()
        {
            string value = "lorem ipsum";

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            string deserializedValue = converter.Deserialize<string>(bytes);

            Assert.Equal(value, deserializedValue);
        }
        public void CanSerialize_ByteArray()
        {
            byte[] value = Encoding.UTF8.GetBytes("lorem ipsum");

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            byte[] deserializedValue = converter.Deserialize<byte[]>(bytes);

            Assert.Equal(value, deserializedValue);
        }
Example #27
0
 protected override T Deserialize(Stream stream)
 {
     return(BinaryConverter.Deserialize <T>(stream));
 }
Example #28
0
 protected override void Serialize(T obj, Stream stream)
 {
     BinaryConverter.Serialize(obj, stream);
 }
Example #29
0
 public static byte[] BinaryStringToByteArray(BotData data, [Variable] string binaryString, bool addPadding = true)
 {
     data.Logger.LogHeader();
     data.Logger.Log($"Converting {binaryString} to a byte array");
     return(BinaryConverter.ToByteArray(binaryString, addPadding));
 }
Example #30
0
        public void Read(byte[] bytes, byte variant, bool reverse)
        {
            Test test = BinaryConverter.FromBytes <Test>(bytes, reverse);

            switch (variant)
            {
            case 1:     //корректный
                Assert.Equal("ab???", test.Field);
                Assert.Equal("AbГг", test.Property);
                Assert.Equal("Dд", test.CountTest1);
                Assert.Equal("Ж   ", test.CountTest2);
                Assert.Equal("Т\xfffd", test.CountTest3);
                Assert.Equal("Ок ", test.ReverseTest1);
                Assert.Equal("Гы", test.ReverseTest2);
                Assert.Equal("Привет!", test.Infinite);
                break;

            case 2:     // недостаточно байтов 1
                Assert.Equal("ab", test.Field);
                Assert.Equal(string.Empty, test.Property);
                Assert.Equal(string.Empty, test.CountTest1);
                Assert.Equal(string.Empty, test.CountTest2);
                Assert.Equal(string.Empty, test.CountTest3);
                Assert.Equal(string.Empty, test.ReverseTest1);
                Assert.Equal(string.Empty, test.ReverseTest2);
                Assert.Equal(string.Empty, test.Infinite);
                break;

            case 3:     // недостаточно байтов 2
                Assert.Equal("ab???", test.Field);
                Assert.Equal("Ab\xfffd", test.Property);
                Assert.Equal(string.Empty, test.CountTest1);
                Assert.Equal(string.Empty, test.CountTest2);
                Assert.Equal(string.Empty, test.CountTest3);
                Assert.Equal(string.Empty, test.ReverseTest1);
                Assert.Equal(string.Empty, test.ReverseTest2);
                Assert.Equal(string.Empty, test.Infinite);
                break;

            case 4:
                Assert.Equal(string.Empty, test.Field);
                Assert.Equal(string.Empty, test.Property);
                Assert.Equal(string.Empty, test.CountTest1);
                Assert.Equal(string.Empty, test.CountTest2);
                Assert.Equal(string.Empty, test.CountTest3);
                Assert.Equal(string.Empty, test.ReverseTest1);
                Assert.Equal(string.Empty, test.ReverseTest2);
                Assert.Equal(string.Empty, test.Infinite);
                break;

            default:
                Assert.Null(test.Field);
                Assert.Null(test.Property);
                Assert.Null(test.CountTest1);
                Assert.Null(test.CountTest2);
                Assert.Null(test.CountTest3);
                Assert.Null(test.ReverseTest1);
                Assert.Null(test.ReverseTest2);
                Assert.Null(test.Infinite);
                break;
            }
        }
Example #31
0
        public void Setup()
        {
            Model.Initialize();
            T deserializedModel;

            /*
             * // Newtonsoft
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  using StreamWriter textWriter = new StreamWriter(stream);
             *  using JsonTextWriter jsonWriter = new JsonTextWriter(textWriter);
             *
             *  var serializer = new Newtonsoft.Json.JsonSerializer();
             *  serializer.Serialize(jsonWriter, Model);
             *  jsonWriter.Flush();
             *
             *  NewtonsoftJsonData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  using StreamReader textReader = new StreamReader(stream);
             *  using JsonTextReader jsonReader = new JsonTextReader(textReader);
             *  deserializedModel = serializer.Deserialize<T>(jsonReader);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with Newtonsoft.Json");
             * }
             *
             * // Binary formatter
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
             *  formatter.Serialize(stream, Model);
             *
             *  BinaryFormatterData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = (T)formatter.Deserialize(stream);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with BinaryFormatter");
             * }
             *
             * // .NETCore JSON
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  using Utf8JsonWriter jsonWriter = new Utf8JsonWriter(stream);
             *
             *  System.Text.Json.JsonSerializer.Serialize(jsonWriter, Model);
             *
             *  DotNetCoreJsonData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = System.Text.Json.JsonSerializer.DeserializeAsync<T>(stream).Result;
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with System.Text.Json");
             * }
             *
             * // DataContractJson
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
             *  serializer.WriteObject(stream, Model);
             *
             *  DataContractJsonData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = (T)serializer.ReadObject(stream);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with DataContractJson");
             * }
             *
             * // XML serializer
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
             *  serializer.Serialize(stream, Model);
             *
             *  XmlSerializerData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = (T)serializer.Deserialize(stream);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with XmlSerializer");
             * }
             *
             * // Portable Xaml
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  Portable.Xaml.XamlServices.Save(stream, Model);
             *
             *  PortableXamlData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  _ = Portable.Xaml.XamlServices.Load(stream);
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with Portable.Xaml");
             * }
             *
             * // Utf8Json
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  Utf8JsonSerializer.Serialize(stream, Model);
             *
             *  Utf8JsonData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = Utf8JsonSerializer.Deserialize<T>(stream);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with Utf8Json");
             * }
             *
             * // MessagePack
             * using (MemoryStream stream = new MemoryStream())
             * {
             *  MessagePack.MessagePackSerializer.Serialize(stream, Model, MessagePack.Resolvers.ContractlessStandardResolver.Instance);
             *
             *  MessagePackData = stream.GetBuffer();
             *
             *  stream.Seek(0, SeekOrigin.Begin);
             *  deserializedModel = MessagePack.MessagePackSerializer.Deserialize<T>(stream, MessagePack.Resolvers.ContractlessStandardResolver.Instance);
             *
             *  if (!Model.Equals(deserializedModel)) throw new InvalidOperationException("Failed comparison with MessagePack");
             * }
             */
            // BinaryPack
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryConverter.Serialize(Model, stream);

                BinaryPackData = stream.GetBuffer();

                stream.Seek(0, SeekOrigin.Begin);
                deserializedModel = BinaryConverter.Deserialize <T>(stream);

                if (!Model.Equals(deserializedModel))
                {
                    throw new InvalidOperationException("Failed comparison with BinaryPack");
                }
            }

            // Apex
            using (MemoryStream stream = new MemoryStream())
            {
                _apex.Write(Model, stream);

                ApexData = stream.GetBuffer();

                stream.Seek(0, SeekOrigin.Begin);
                deserializedModel = _apex.Read <T>(stream);

                if (!Model.Equals(deserializedModel))
                {
                    throw new InvalidOperationException("Failed comparison with Apex");
                }
            }
        }
        protected override bool OnWriteResume(BinaryWriter writer, TCollection value, BinarySerializerOptions options, ref WriteStack state)
        {
            IEnumerator <TElement> enumerator;

            if (state.Current.CollectionEnumerator == null)
            {
                enumerator = value.GetEnumerator();
                if (!enumerator.MoveNext())
                {
                    return(true);
                }
            }
            else
            {
                enumerator = (IEnumerator <TElement>)state.Current.CollectionEnumerator;
            }

            BinaryConverter <TElement> converter = GetElementConverter(ref state);
            int index = state.Current.EnumeratorIndex;

            if (!state.SupportContinuation)
            {
                do
                {
                    state.Current.WriteEnumerableIndex(index, writer);
                    TElement element = enumerator.Current;
                    converter.TryWrite(writer, element, options, ref state);
                    // 列表状态下,每个写每个元素时独立的,故需清理多态属性
                    state.Current.PolymorphicBinaryPropertyInfo = null;
                    index++;
                } while (enumerator.MoveNext());
            }
            else
            {
                do
                {
                    if (ShouldFlush(writer, ref state))
                    {
                        state.Current.CollectionEnumerator = enumerator;
                        return(false);
                    }

                    if (!state.Current.ProcessedEnumerableIndex)
                    {
                        state.Current.WriteEnumerableIndex(index, writer);
                        state.Current.ProcessedEnumerableIndex = true;
                    }

                    TElement element = enumerator.Current;
                    if (!converter.TryWrite(writer, element, options, ref state))
                    {
                        state.Current.CollectionEnumerator = enumerator;
                        state.Current.EnumeratorIndex      = index;
                        return(false);
                    }

                    // 列表状态下,每个写每个元素时独立的,故需清理多态属性
                    state.Current.PolymorphicBinaryPropertyInfo = null;
                    state.Current.ProcessedEnumerableIndex      = false;
                    index++;
                } while (enumerator.MoveNext());
            }

            return(true);
        }
Example #33
0
        public void BinaryPack2()
        {
            using Stream stream = new MemoryStream(BinaryPackData);

            _ = BinaryConverter.Deserialize <T>(stream);
        }
        public void CanSerialize_Bool()
        {
            bool value = false;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            bool deserializedValue = converter.Deserialize<bool>(bytes);

            Assert.Equal(value, deserializedValue);
        }
Example #35
0
 public void Setup()
 {
     _converter = new BinaryConverter();
 }
        public void CanSerialize_Decimal()
        {
            decimal value = decimal.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            decimal deserializedValue = converter.Deserialize<decimal>(bytes);

            Assert.Equal(value, deserializedValue);
        }
 public void AppendDateTime(DateTime value, BinaryConverter converter)
 {
     AppendBytes(converter.GetBytes(value));
 }
        public void CanSerialize_Datetime()
        {
            DateTime value = DateTime.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            DateTime deserializedValue = converter.Deserialize<DateTime>(bytes);

            Assert.Equal(value, deserializedValue);
        }
 public void OutputsString_NegativeInput()
 {
     int             input           = -5;
     BinaryConverter binaryConverter = new BinaryConverter(input);
 }
        public void CanSerializeAndDeserializeNestedTypes()
        {
            Test model = new Test
            {
                Two = new TestTwo
                {
                    Message = "lorem",
                    Three = new TestThree
                    {
                        Date = DateTime.Now,
                        Z = 5
                    }
                },
                X = 1
            };

            BinaryConverter converter = new BinaryConverter();
            byte[] array = converter.Serialize(model);
            Test objFromBytes = converter.Deserialize<Test>(array);

            Assert.Equal(objFromBytes.X, model.X);
            Assert.Equal(objFromBytes.Two.Message, model.Two.Message);
            Assert.Equal(objFromBytes.Two.Three.Date, model.Two.Three.Date);
            Assert.Equal(objFromBytes.Two.Three.Z, model.Two.Three.Z);
        }
Example #41
0
 public NullableConverter(BinaryConverter <T> converter)
 {
     _converter = converter;
 }
        public void CanSerializeAndDeserializeNestedTypeWithByteArray()
        {
            TestFour model = new TestFour
            {
                ByteArray = new ByteArray
                {
                    Array = Encoding.UTF8.GetBytes("lorem ipsum")
                },
                X = 15
            };

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(model);
            TestFour modelFromBytes = converter.Deserialize<TestFour>(bytes);

            Assert.Equal(modelFromBytes.X, model.X);
            Assert.Equal(modelFromBytes.ByteArray.Array, model.ByteArray.Array);
        }
 public void OutputDecimal_NegativeInput()
 {
     int             input           = -8675309;
     BinaryConverter binaryConverter = new BinaryConverter(input);
 }
Example #44
0
        float CreateFloat(char[] chars)
        {
            var bytes = BinaryConverter.CharsToBytes(chars);

            return(BitConverter.ToSingle(bytes, 0));
        }
        //internal BinaryCrossAppDomainMap crossAppDomainMap;

        internal void WriteObject(NameInfo nameInfo, NameInfo typeNameInfo, int numMembers, String[] memberNames, Type[] memberTypes, WriteObjectInfo[] memberObjectInfos)
        {
            InternalWriteItemNull();
            int assemId;

#if _DEBUG
            nameInfo.Dump("WriteObject nameInfo");
            typeNameInfo.Dump("WriteObject typeNameInfo");
#endif

            int objectId = (int)nameInfo.NIobjectId;

            //if (objectId < 0)
            //  objectId = --m_nestedObjectCount;

            if (objectId > 0)
            {
                BCLDebug.Trace("BINARY", "-----Top Level Object-----");
            }

            String objectName = null;
            if (objectId < 0)
            {
                // Nested Object
                objectName = typeNameInfo.NIname;
            }
            else
            {
                // Non-Nested
                objectName = nameInfo.NIname;
            }
            SerTrace.Log(this, "WriteObject objectName ", objectName);

            if (objectMapTable == null)
            {
                objectMapTable = new Hashtable();
            }

            ObjectMapInfo objectMapInfo = (ObjectMapInfo)objectMapTable[objectName];

            if (objectMapInfo != null && objectMapInfo.isCompatible(numMembers, memberNames, memberTypes))
            {
                // Object
                if (binaryObject == null)
                {
                    binaryObject = new BinaryObject();
                }
                binaryObject.Set(objectId, objectMapInfo.objectId);
#if _DEBUG
                binaryObject.Dump();
#endif
                binaryObject.Write(this);
            }
            else if (!typeNameInfo.NItransmitTypeOnObject)
            {
                // ObjectWithMap
                if (binaryObjectWithMap == null)
                {
                    binaryObjectWithMap = new BinaryObjectWithMap();
                }

                // BCL types are not placed into table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMap.Set(objectId, objectName, numMembers, memberNames, assemId);

                binaryObjectWithMap.Dump();
                binaryObjectWithMap.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
            else
            {
                // ObjectWithMapTyped
                BinaryTypeEnum[] binaryTypeEnumA  = new BinaryTypeEnum[numMembers];
                Object[]         typeInformationA = new Object[numMembers];
                int[]            assemIdA         = new int[numMembers];
                for (int i = 0; i < numMembers; i++)
                {
                    Object typeInformation = null;

                    binaryTypeEnumA[i]  = BinaryConverter.GetBinaryTypeInfo(memberTypes[i], memberObjectInfos[i], null, objectWriter, out typeInformation, out assemId);
                    typeInformationA[i] = typeInformation;
                    assemIdA[i]         = assemId;

                    /*SerTrace.Log( this, "WriteObject ObjectWithMapTyped memberNames "
                     *            ,memberNames[i],", memberType ",memberTypes[i]," binaryTypeEnum ",((Enum)binaryTypeEnumA[i]).ToString()
                     *            ,", typeInformation ",typeInformationA[i]," assemId ",assemIdA[i]);*/
                }

                if (binaryObjectWithMapTyped == null)
                {
                    binaryObjectWithMapTyped = new BinaryObjectWithMapTyped();
                }

                // BCL types are not placed in table
                assemId = (int)typeNameInfo.NIassemId;
                binaryObjectWithMapTyped.Set(objectId, objectName, numMembers, memberNames, binaryTypeEnumA, typeInformationA, assemIdA, assemId);
#if _DEBUG
                binaryObjectWithMapTyped.Dump();
#endif
                binaryObjectWithMapTyped.Write(this);
                if (objectMapInfo == null)
                {
                    objectMapTable.Add(objectName, new ObjectMapInfo(objectId, numMembers, memberNames, memberTypes));
                }
            }
        }
        public void CanSerialize_Ulong()
        {
            ulong value = ulong.MinValue;

            BinaryConverter converter = new BinaryConverter();
            byte[] bytes = converter.Serialize(value);
            ulong deserializedValue = converter.Deserialize<ulong>(bytes);

            Assert.Equal(value, deserializedValue);
        }
Example #47
0
        public void NotExistsBinaryToCsvWriteTest()
        {
            BaseConverter converter = new BinaryConverter(String.Empty, DocumentTypeEnum.Csv);

            converter.ReadAndWrite();
        }