public override void WriteBody(OperationBuilder builder)
        {
            using (var bufferOwner = MemoryPool <byte> .Shared.Rent(OperationSpec.MaxPathLength))
            {
                var buffer = bufferOwner.Memory.Span;

                var pathLength = Converter.FromString(Path, buffer);

                builder.Write(bufferOwner.Memory.Slice(0, pathLength));
            }

            if (!CurrentSpec.RemoveBrackets)
            {
                // We can serialize directly
                Transcoder.Serializer.Serialize(builder, CurrentSpec.Value);
            }
            else
            {
                using (var stream = MemoryStreamFactory.GetMemoryStream())
                {
                    Transcoder.Serializer.Serialize(stream, CurrentSpec.Value);

                    ReadOnlyMemory <byte> body = stream.GetBuffer().AsMemory(0, (int)stream.Length);
                    body = body.StripBrackets();

                    builder.Write(body);
                }
            }
        }
Esempio n. 2
0
        private void WriteSpecValue(OperationBuilder builder, OperationSpec spec)
        {
            if (!spec.RemoveBrackets)
            {
                // We can serialize directly
                Transcoder.Serializer.Serialize(builder, spec.Value);
            }
            else
            {
                using (var stream = MemoryStreamFactory.GetMemoryStream())
                {
                    Transcoder.Serializer.Serialize(stream, spec.Value);

                    ReadOnlyMemory <byte> bytes = stream.GetBuffer().AsMemory(0, (int)stream.Length);
                    bytes = bytes.StripBrackets();

                    builder.Write(bytes);
                }
            }
        }