Example #1
0
        public byte[] WriteGroupCommand(RedisGroupCommand command)
        {
            // Written as a MessagePack 'arr' containing at least these items:
            // * An 'int': the Id of the command
            // * A 'str': The server name
            // * An 'int': The action (likely less than 0x7F and thus a single-byte fixnum)
            // * A 'str': The group name
            // * A 'str': The connection Id
            // Any additional items are discarded.

            var writer = MemoryBufferWriter.Get();

            try
            {
                MessagePackBinary.WriteArrayHeader(writer, 5);
                MessagePackBinary.WriteInt32(writer, command.Id);
                MessagePackBinary.WriteString(writer, command.ServerName);
                MessagePackBinary.WriteByte(writer, (byte)command.Action);
                MessagePackBinary.WriteString(writer, command.GroupName);
                MessagePackBinary.WriteString(writer, command.ConnectionId);

                return(writer.ToArray());
            }
            finally
            {
                MemoryBufferWriter.Return(writer);
            }
        }
Example #2
0
        public byte[] WriteGroupCommand(RedisGroupCommand command)
        {
            // Group Command Format:
            // * Variable length integer: Id
            // * Length prefixed string: ServerName
            // * 1 byte: Action
            // * Length prefixed string: GroupName
            // * Length prefixed string: ConnectionId

            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriterWithVarInt(stream, _utf8NoBom))
                {
                    writer.WriteVarInt(command.Id);
                    writer.Write(command.ServerName);
                    writer.Write((byte)command.Action);
                    writer.Write(command.GroupName);
                    writer.Write(command.ConnectionId);
                    return(stream.ToArray());
                }
        }