示例#1
0
        public bool WriteQueryCommand(ref CommandListPosition commandListPosition, IDictionary <string, CachedProcedure?> cachedProcedures, ByteBufferWriter writer)
        {
            writer.Write((byte)CommandKind.Multi);
            bool?firstResult = default;
            bool wroteCommand;

            do
            {
                // save room for command length
                var position = writer.Position;
                writer.Write(Padding);

                wroteCommand = SingleCommandPayloadCreator.Instance.WriteQueryCommand(ref commandListPosition, cachedProcedures, writer);
                if (firstResult is null)
                {
                    firstResult = wroteCommand;
                }

                // write command length
                var commandLength = writer.Position - position - Padding.Length;
                var span          = writer.ArraySegment.AsSpan().Slice(position);
                span[0] = 0xFE;
                BinaryPrimitives.WriteUInt64LittleEndian(span.Slice(1), (ulong)commandLength);
            } while (wroteCommand);

            // remove the padding that was saved for the final command (which wasn't written)
            writer.TrimEnd(Padding.Length);
            return(firstResult.Value);
        }