Esempio n. 1
0
 protected internal override void WriteOptions(OutputStream ostr)
 {
     Debug.Assert(Protocol != Protocol.Ice1);
     if (_resource != "/")
     {
         ostr.WriteSize(1);
         ostr.WriteString(_resource);
     }
     else
     {
         ostr.WriteSize(0);
     }
 }
Esempio n. 2
0
        internal override async ValueTask SendAsync(
            long streamId,
            OutgoingFrame frame,
            bool fin,
            CancellationToken cancel)
        {
            var       data      = new List <ArraySegment <byte> >();
            var       ostr      = new OutputStream(Encoding, data);
            FrameType frameType = fin ? FrameType.StreamLast : FrameType.Stream;

            ostr.WriteByte((byte)frameType);
            OutputStream.Position sizePos = ostr.StartFixedLengthSize(4);
            ostr.WriteVarLong(streamId);
            OutputStream.Position ice2HeaderPos = ostr.Tail;
            if (frame is OutgoingRequestFrame requestFrame)
            {
                ostr.WriteByte((byte)Ice2Definitions.FrameType.Request);
            }
            else if (frame is OutgoingResponseFrame responseFrame)
            {
                ostr.WriteByte((byte)Ice2Definitions.FrameType.Response);
            }
            else
            {
                Debug.Assert(false);
                return;
            }
            ostr.WriteSize(frame.Size);
            int ice2HeaderSize = ostr.Tail.Offset - ice2HeaderPos.Offset;

            data[^ 1] = data[^ 1].Slice(0, ostr.Tail.Offset); // TODO: Shouldn't this be the job of ostr.Finish()?
Esempio n. 3
0
 protected internal override void WriteOptions(OutputStream ostr)
 {
     if (Protocol == Protocol.Ice1)
     {
         base.WriteOptions(ostr);
         ostr.WriteString(_resource);
     }
     else
     {
         if (_resource != "/")
         {
             ostr.WriteSize(1);
             ostr.WriteString(_resource);
         }
         else
         {
             ostr.WriteSize(0); // empty sequence of options
         }
     }
 }
Esempio n. 4
0
            public override void Flush()
            {
                // _pos represents the size

                try
                {
                    if (_data != null)
                    {
                        Debug.Assert(_stream.OldEncoding);
                        Debug.Assert(_pos <= _data.Length);
                        _stream.WriteSize(_pos); // 1 byte size length
                        _stream.WriteByteSpan(_data.AsSpan(0, _pos));
                    }
                    else
                    {
                        // Patch previously-written dummy value.

                        if (_stream.OldEncoding)
                        {
                            Debug.Assert(_pos >= 255);
                            Span <byte> data = stackalloc byte[5];
                            data[0] = 255;
                            OutputStream.WriteInt(_pos, data.Slice(1, 4));
                            _stream.RewriteByteSpan(data, _startPos);
                        }
                        else
                        {
                            Span <byte> data = stackalloc byte[OutputStream.DefaultSizeLength];
                            OutputStream.WriteFixedLengthSize20(_pos, data);
                            _stream.RewriteByteSpan(data, _startPos);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new IOException("could not flush stream", ex);
                }
            }
Esempio n. 5
0
        private protected void WriteBinaryContext(OutputStream ostr)
        {
            Debug.Assert(Protocol == Protocol.Ice2);
            Debug.Assert(ostr.Encoding == Encoding.V20);

            int sizeLength =
                OutputStream.GetSizeLength20(InitialBinaryContext.Count + (_binaryContextOverride?.Count ?? 0));

            int size = 0;

            OutputStream.Position start = ostr.StartFixedLengthSize(sizeLength);

            // First write the overrides, then the InitialBinaryContext entries that were not overridden.

            if (_binaryContextOverride is Dictionary <int, Action <OutputStream> > binaryContextOverride)
            {
                foreach ((int key, Action <OutputStream> action) in binaryContextOverride)
                {
                    ostr.WriteVarInt(key);
                    OutputStream.Position startValue = ostr.StartFixedLengthSize(2);
                    action(ostr);
                    ostr.EndFixedLengthSize(startValue, 2);
                    size++;
                }
            }
            foreach ((int key, ReadOnlyMemory <byte> value) in InitialBinaryContext)
            {
                if (_binaryContextOverride == null || !_binaryContextOverride.ContainsKey(key))
                {
                    ostr.WriteVarInt(key);
                    ostr.WriteSize(value.Length);
                    ostr.WriteByteSpan(value.Span);
                    size++;
                }
            }
            ostr.RewriteFixedLengthSize20(size, start, sizeLength);
        }