示例#1
0
        byte[] BuildMessage <T>(int methodId, T value, Guid[] connectionIds, bool isExcept)
        {
            var rent = System.Buffers.ArrayPool <byte> .Shared.Rent(ushort.MaxValue);

            var buffer = rent;

            try
            {
                var offset = 0;

                // redis-format: [isExcept, [connectionIds], [raw-bloadcast-format]]
                offset += MessagePackBinary.WriteArrayHeader(ref buffer, offset, 3);
                offset += MessagePackBinary.WriteBoolean(ref buffer, offset, isExcept);
                offset += NativeGuidArrayFormatter.Serialize(ref buffer, offset, connectionIds);

                offset += MessagePackBinary.WriteArrayHeader(ref buffer, offset, 2);
                offset += MessagePackBinary.WriteInt32(ref buffer, offset, methodId);
                offset += LZ4MessagePackSerializer.SerializeToBlock(ref buffer, offset, value, resolver);

                var result = MessagePackBinary.FastCloneWithResize(buffer, offset);
                return(result);
            }
            finally
            {
                System.Buffers.ArrayPool <byte> .Shared.Return(rent);
            }
        }
示例#2
0
        static Task PublishFromRedisToMemoryGroup(RedisValue value, IGroup group)
        {
            byte[] buffer = value;
            var    reader = new MessagePackReader(buffer);

            var len1 = reader.ReadArrayHeader();

            if (len1 == 3)
            {
                var isExcept = reader.ReadBoolean();
                if (isExcept)
                {
                    var excludes = NativeGuidArrayFormatter.Deserialize(ref reader);
                    var offset   = (int)reader.Consumed;
                    return(group.WriteExceptRawAsync(new ArraySegment <byte>(buffer, offset, buffer.Length - offset), excludes, fireAndForget: false));
                }
                else
                {
                    var includes = NativeGuidArrayFormatter.Deserialize(ref reader);
                    var offset   = (int)reader.Consumed;
                    return(group.WriteToRawAsync(new ArraySegment <byte>(buffer, offset, buffer.Length - offset), includes, fireAndForget: false));
                }
            }

            return(Task.CompletedTask);
        }
示例#3
0
        static Task PublishFromRedisToMemoryGroup(RedisValue value, IGroup group)
        {
            byte[] buffer = value;
            var    offset = 0;
            int    readSize;
            var    len1 = MessagePackBinary.ReadArrayHeader(buffer, offset, out readSize);

            offset += readSize;
            if (len1 == 2)
            {
                var excludes = NativeGuidArrayFormatter.Deserialize(buffer, offset, out readSize);
                offset += readSize;

                return(group.WriteRawAsync(new ArraySegment <byte>(buffer, offset, buffer.Length - offset), excludes, fireAndForget: false));
            }

            return(Task.CompletedTask);
        }
示例#4
0
        byte[] BuildMessage <T>(int methodId, T value, Guid[] connectionIds, bool isExcept)
        {
            using (var buffer = ArrayPoolBufferWriter.RentThreadStaticWriter())
            {
                // redis-format: [isExcept, [connectionIds], [raw-bloadcast-format]]
                var writer = new MessagePackWriter(buffer);

                writer.WriteArrayHeader(3);
                writer.Write(isExcept);
                NativeGuidArrayFormatter.Serialize(ref writer, connectionIds);

                writer.WriteArrayHeader(2);
                writer.WriteInt32(methodId);
                MessagePackSerializer.Serialize(ref writer, value, serializerOptions);

                writer.Flush();
                var result = buffer.WrittenSpan.ToArray();
                return(result);
            }
        }