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); } }
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); } }