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: true)); } 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: true)); } } return(Task.CompletedTask); }
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); } }