protected override void PackToCore(Packer packer, Message message)
        {
            packer.PackMapHeader(message.Data.Count + 2); // accomodate for all fields, topic and stamp

            packer.PackString("Topic");
            packer.PackString(message.Topic);

            packer.PackString("Stamp");
            packer.PackExtendedTypeValue(Code["Time"], TimeSerializer.PackSingleObject(message.TimeStamp));

            foreach (var fieldName in message.Fields)
            {
                packer.PackString(fieldName);

                var bin = message[fieldName];
                if (bin.Count == 1)
                {
                    var alias = TypeIdentity.Instance.FindAlias(bin.GetInnerType());
                    PackSlice(packer, alias, bin.First);
                }
                else
                {
                    packer.PackArrayHeader(bin.Count);
                    var alias = TypeIdentity.Instance.FindAlias(bin.GetInnerType());
                    foreach (var item in bin)
                    {
                        PackSlice(packer, alias, item);
                    }
                }
            }
        }
Beispiel #2
0
        protected override void PackToCore(Packer packer, Message message)
        {
            var serializable = (
                from fieldName in message.Data.Keys
                let bin = message[fieldName]
                          where bin != null
                          let typeRecord = TypeIdentity.Instance[bin.GetInnerType()]
                                           where typeRecord != null
                                           where typeRecord.CloneMethod != CloneBehaviour.Null
                                           select fieldName
                ).ToList();

            packer.PackMapHeader(serializable.Count + 2); // accomodate for all fields, topic and stamp

            packer.PackString("Topic");
            packer.PackString(message.Topic);

            packer.PackString("Stamp");
            packer.PackExtendedTypeValue(Code["Time"], TimeSerializer.PackSingleObject(message.TimeStamp));

            foreach (var fieldName in serializable)
            {
                var bin        = message[fieldName];
                var typeRecord = TypeIdentity.Instance[bin.GetInnerType()];

                packer.PackString(fieldName);

                if (bin.Count == 1)
                {
                    var alias = typeRecord.Alias;
                    PackSlice(packer, alias, bin.First);
                }
                else
                {
                    packer.PackArrayHeader(bin.Count);
                    var alias = typeRecord.Alias;
                    foreach (var item in bin)
                    {
                        PackSlice(packer, alias, item);
                    }
                }
            }
        }