Exemple #1
0
        public void PackToMessage(Packer packer, PackingOptions options)
        {
            packer.PackMapHeader(2);
            packer.Pack("__type");
            packer.Pack("MetaField");

            packer.Pack("fieldId");
            packer.Pack(FieldId);
        }
 public void PackToMessage(Packer packer, PackingOptions options)
 {
     packer.PackMapHeader(3);
     packer.PackString("graphName");
     packer.Pack(this.graphName);
     packer.PackString("graphObjName");
     packer.Pack(this.graphObjName);
     packer.PackString("killSession");
     packer.Pack(this.killSession);
 }
Exemple #3
0
        protected override void PackToCore(MsgPack.Packer packer, IO.Ably.Message objectTree)
        {
            var nonNullFields = new bool[]
            {
                objectTree.ClientId.IsNotEmpty(),
                objectTree.ConnectionId.IsNotEmpty(),
                objectTree.Data != null,
                objectTree.Encoding.IsNotEmpty(),
                objectTree.Id.IsNotEmpty(),
                objectTree.Name.IsNotEmpty(),
                objectTree.Timestamp != null,
            }.Count(x => x);

            packer.PackMapHeader(nonNullFields);
            if (objectTree.ClientId.IsNotEmpty())
            {
                this._serializer0.PackTo(packer, "clientId");
                this._serializer0.PackTo(packer, objectTree.ClientId);
            }
            if (objectTree.ConnectionId.IsNotEmpty())
            {
                this._serializer0.PackTo(packer, "connectionId");
                this._serializer0.PackTo(packer, objectTree.ConnectionId);
            }
            if (objectTree.Data != null)
            {
                this._serializer0.PackTo(packer, "data");
                this._serializer1.PackTo(packer, objectTree.Data);
            }
            if (objectTree.Encoding.IsNotEmpty())
            {
                this._serializer0.PackTo(packer, "encoding");
                this._serializer0.PackTo(packer, objectTree.Encoding);
            }
            if (objectTree.Id.IsNotEmpty())
            {
                this._serializer0.PackTo(packer, "id");
                this._serializer0.PackTo(packer, objectTree.Id);
            }
            if (objectTree.Name.IsNotEmpty())
            {
                this._serializer0.PackTo(packer, "name");
                this._serializer0.PackTo(packer, objectTree.Name);
            }
            if (objectTree.Timestamp != null)
            {
                this._serializer0.PackTo(packer, "timestamp");
                this._serializer2.PackTo(packer, objectTree.Timestamp);
            }
        }
Exemple #4
0
        public static bool MsgPackLuaTable(ref LuaTable luatable, ref Packer pker)
        {

            if (luatable == null)
            {
                pker = null;
                return false;
            }
            else
            {
                pker.PackMapHeader(luatable.Count);
            }
            foreach (var item in luatable)
            {
                //object key = item.Key;
                bool kFlag = luatable.IsKeyString(item.Key);
                if (kFlag)
                {
                    pker.PackRawHeader(item.Key.Length);
                    pker.PackRawBody(System.Text.Encoding.UTF8.GetBytes(item.Key));
                }
                else
                {
                    pker.Pack(double.Parse(item.Key.ToString()));
                }

                var valueType = item.Value.GetType();
                if (valueType == typeof(String))
                {

                    pker.PackRawHeader(item.Value.ToString().Length);
                    pker.PackRawBody(System.Text.Encoding.UTF8.GetBytes(item.Value.ToString()));
                }
                else if (valueType == typeof(LuaTable))
                {
                    LuaTable luaTbl = item.Value as LuaTable;
                    MsgPackLuaTable(ref luaTbl, ref pker);
                }
                else if (valueType == typeof(bool))
                {
                    pker.Pack(bool.Parse(item.Value.ToString()));
                }
                else
                {
                    pker.Pack(double.Parse(item.Value.ToString()));
                }
            }
            return true;
        }
        public void PackToMessage(Packer packer, PackingOptions options)
        {
            packer.PackMapHeader(this.inSession ? 4 : 6)
                  .PackString("channel")
                  .Pack(Channel.MsgPack)
                  .PackString("inSession")
                  .Pack(this.inSession)
                  .PackString("isolate")
                  .Pack(this.isolate)
                  .PackString("transaction")
                  .Pack(this.transaction);

            if (!this.inSession)
            {
                packer.PackString("graphName")
                      .PackString(this.graphName)
                      .PackString("graphObjName")
                      .PackString(this.graphObjName);
            }
        }
Exemple #6
0
        /// <summary>
        ///     Packs the candidate to a MessagePack objects
        ///     This method should not be called directly, use serialize instead.
        /// </summary>
        /// <param name="packer">The packer</param>
        /// <param name="options">The packer options</param>
        public void PackToMessage(Packer packer, PackingOptions options)
        {
            // pack the header for the amount of items in the map
            packer.PackMapHeader(MapCount);

            packer.Pack("DCS");
            packer.Pack(Dcs);

            packer.Pack("DAC");
            packer.Pack(Dac);

            packer.Pack("DAD");
            packer.Pack(Dad);

            packer.Pack("DBD");
            packer.Pack(Dbd.ToString(DateFormat, CultureInfo.InvariantCulture));

            packer.Pack("DBB");
            packer.Pack(Dbb.ToString(DateFormat, CultureInfo.InvariantCulture));

            packer.Pack("DBC");
            packer.Pack((int) Dbc);

            packer.Pack("DAY");
            packer.Pack(Day.AnsiFormat());

            packer.Pack("DAU");
            packer.Pack(Dau.AnsiFormat);

            packer.Pack("DAG");
            packer.Pack(Dag);

            packer.Pack("DAI");
            packer.Pack(Dai);

            packer.Pack("DAJ");
            packer.Pack(Daj);

            packer.Pack("DAK");
            packer.Pack(Dak.AnsiFormat);

            packer.Pack("DCG");
            packer.Pack(Dcg);

            // pack image
            packer.Pack("ZAA");
            var imageConverter = new ImageConverter();
            packer.Pack((byte[]) imageConverter.ConvertTo(Image, typeof (byte[])));

            // pack fingerprint
            packer.Pack("ZAB");

            if (Fingerprint.Image != null) {
                var afis = new AfisEngine();
                var p = new Person(Fingerprint);
                afis.Extract(p);
            }
            if (Fingerprint.AsIsoTemplate != null) packer.Pack(Fingerprint.AsIsoTemplate);
        }
        void Pack(Packer packer, object o)
        {
            if (o == null) {
                packer.PackNull();
                return;
            }

            if (o is int)
                packer.Pack ((int)o);
            else if (o is uint)
                packer.Pack ((uint)o);
            else if (o is float)
                packer.Pack ((float)o);
            else if (o is double)
                packer.Pack ((double)o);
            else if (o is long)
                packer.Pack ((long)o);
            else if (o is ulong)
                packer.Pack ((ulong)o);
            else if (o is bool)
                packer.Pack ((bool)o);
            else if (o is byte)
                packer.Pack ((byte)o);
            else if (o is sbyte)
                packer.Pack ((sbyte)o);
            else if (o is short)
                packer.Pack ((short)o);
            else if (o is ushort)
                packer.Pack ((ushort)o);
            else if (o is string)
                packer.PackString((string)o, Encoding.ASCII);
            else if (o is Dictionary<string, object>)
            {
                packer.PackMapHeader((o as Dictionary<string, object>).Count);

                foreach (var pair in (o as Dictionary<string, object>))
                {
                    Pack(packer, pair.Key);
                    Pack(packer, pair.Value);
                }

            }
            else if (o is string[])
            {
                packer.PackArrayHeader((o as string[]).Length);

                foreach (var obj in (o as string[]))
                    packer.Pack(obj as string);
            }
            else
                throw new Exception("Cant handle type: " + o.GetType().Name);;
        }