Exemple #1
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()?
Exemple #2
0
            public override void WriteByte(byte value)
            {
                try
                {
                    if (_data != null)
                    {
                        // If we can fit the data into the first 254 bytes, write it to _data.
                        if (_pos < _data.Length)
                        {
                            _data[_pos++] = value;
                            return;
                        }

                        // Dummy size, until we know how big the stream really is and can patch the size.
                        _stream.WriteSize(255);
                        if (_pos > 0)
                        {
                            // Write the current contents of _data.
                            _stream.WriteByteSpan(_data.AsSpan(0, _pos));
                        }

                        _data = null;
                    }

                    // Write data passed by caller.
                    _stream.WriteByte(value);
                    _pos += 1;
                }
                catch (Exception ex)
                {
                    throw new IOException("could not write to stream", ex);
                }
            }
Exemple #3
0
        /// <summary>Creates a new outgoing response frame with a void return value.</summary>
        /// <param name="current">The Current object for the corresponding incoming request.</param>
        /// <returns>A new OutgoingResponseFrame.</returns>
        public static OutgoingResponseFrame WithVoidReturnValue(Current current)
        {
            var data = new List <ArraySegment <byte> >();
            var ostr = new OutputStream(current.Protocol.GetEncoding(), data);

            ostr.WriteByte((byte)ResultType.Success);
            _ = ostr.WriteEmptyEncapsulation(current.Encoding);
            return(new OutgoingResponseFrame(current.Protocol, current.Encoding, data, ostr.Tail));
        }
 internal static void WriteProxyData11(
     this OutputStream ostr,
     string facet,
     InvocationMode invocationMode,
     Protocol protocol,
     Encoding encoding)
 {
     Debug.Assert(ostr.Encoding == Encoding.V11);
     ostr.WriteIce1Facet(facet);
     ostr.Write(invocationMode);
     ostr.WriteBool(false); // "secure"
     ostr.Write(protocol);
     ostr.WriteByte(0);     // protocol minor
     encoding.IceWrite(ostr);
 }