Пример #1
0
    public byte[] Pack()
    {
        stream = new MemoryStream();
        if (transport == null)
        {
            transport = new TStreamTransport(null, stream);
        }
        else
        {
            transport.OutputStream = stream;
        }

        if (protocol == null)
        {
            protocol = new TCompactProtocol(transport);
        }
        else
        {
            protocol.reset();
            protocol.Transport = transport;
        }

        protocol.WriteStructBegin(struc);

        fieldWriter.Name = "context";
        fieldWriter.Type = TType.Map;
        fieldWriter.ID   = 1;
        protocol.WriteFieldBegin(fieldWriter);
        {
            protocol.WriteMapBegin(new TMap(TType.String, TType.Struct, context.Count));
            foreach (string _iter44 in context.Keys)
            {
                protocol.WriteString(_iter44);
                context[_iter44].Write(fieldWriter, protocol);
            }
            protocol.WriteMapEnd();
        }
        protocol.WriteFieldEnd();

        fieldWriter.Name = "events";
        fieldWriter.Type = TType.Map;
        fieldWriter.ID   = 2;
        protocol.WriteFieldBegin(fieldWriter);
        {
            protocol.WriteMapBegin(new TMap(TType.String, TType.Struct, events.Count));
            foreach (string _iter44 in events.Keys)
            {
                protocol.WriteString(_iter44);
                events[_iter44].Write(fieldWriter, protocol);
            }
            protocol.WriteMapEnd();
        }
        protocol.WriteFieldEnd();

        protocol.WriteFieldStop();
        protocol.WriteStructEnd();

        return(stream.ToArray());
    }
Пример #2
0
    public void Write(TField writer, TCompactProtocol protocol)
    {
        protocol.WriteStructBegin(new TStruct(GetType().ToString()));

        writer.Name = "type";
        writer.Type = TType.String;
        writer.ID   = 1;
        protocol.WriteFieldBegin(writer);
        protocol.WriteString(type);
        protocol.WriteFieldEnd();

        WriteFields(writer, protocol);

        protocol.WriteFieldStop();
        protocol.WriteStructEnd();
    }
Пример #3
0
    public void Write(TField writer, TCompactProtocol protocol)
    {
        protocol.WriteStructBegin(struc);

        writer.Name = "properties";
        writer.Type = TType.Map;
        writer.ID   = 1;
        protocol.WriteFieldBegin(writer);
        {
            protocol.WriteMapBegin(new TMap(TType.String, TType.Struct, properties.Count));
            foreach (string _iter44 in properties.Keys)
            {
                protocol.WriteString(_iter44);
                properties[_iter44].Write(writer, protocol);
            }
            protocol.WriteMapEnd();
        }
        protocol.WriteFieldEnd();

        protocol.WriteFieldStop();
        protocol.WriteStructEnd();
    }
Пример #4
0
        publish(string topic_name, message_base msg, WaypointsType waypoints = null, bool send_as_delta = false, byte[] stream_id = null, long message_sequence_number = 0, ulong micros_since_epoch = 0)
        {
            unchecked {
                MemoryStream stream = new MemoryStream();
                var          proto  = new TCompactProtocol(new TStreamTransport(stream, stream));

                proto.WriteByte(1);

                uint flags = 0;
                if (waypoints != null)
                {
                    flags |= (uint)message_envelope <WaypointsType> .flags_enum.has_waypoints;
                }
                if (send_as_delta == true)
                {
                    flags |= (uint)message_envelope <WaypointsType> .flags_enum.is_delta;
                }
                if (stream_id != null)
                {
                    flags |= (uint)message_envelope <WaypointsType> .flags_enum.has_stream_id;
                }
                proto.WriteI32((int)flags);

                proto.WriteString(msg.GetType().Name);

                if (stream_id != null)
                {
                    proto.WriteBinary(stream_id);
                }

                if (waypoints != null)
                {
                    waypoints.Write(proto);
                }

                msg.Write(proto, !send_as_delta);

                Publishing_channel channel;
                string             topic_name_;
                lock (publishing_channels) {
                    if (!publishing_channels.TryGetValue(topic_name, out channel))
                    {
                        channel = new Publishing_channel(conn, Publishing_channel_idle_timeout, topic_name, publishing_channels, publishing_exception);
                        publishing_channels[topic_name] = channel;
                        topic_name_ = topic_name;
                    }
                    else
                    {
                        topic_name_ = "";
                    }

                    // publishing_channel.QueueDeclare(topic_name, false, false, false, null);
                    // not too fast at the moment (bare bones example), TODO later will set topic_name elsewhere so as not to resend it everytime

                    // explicit since epoch in microseconds time for the server's requirements
                    // TODO -- perhaps drop seq. number altogether or provide individually-parsable (at the server end) possibility of supplying either one, or both (currently it is both or none thereby wasting at times 8 bytes)...
                    IBasicProperties props_;
                    if (micros_since_epoch != 0 || message_sequence_number != 0)
                    {
                        var dictionary = new Dictionary <string, object>();
                        dictionary.Add("XXXXXX", (long)message_sequence_number);
                        if (props == null)
                        {
                            props = channel.AMQP_channel.CreateBasicProperties();
                        }
                        props.ContentType = "X";
                        props.Headers     = dictionary;
                        props.Timestamp   = new AmqpTimestamp((long)micros_since_epoch);
                        props_            = props;
                    }
                    else
                    {
                        props_ = null;
                    }
                    channel.Published_flag = true;
                    channel.AMQP_channel.BasicPublish("", topic_name_, props_, stream.ToArray());
                }
                return(stream.Length);
            }
        }