public static bool TryParse(ReadableBuffer payload, out WebSocketCloseResult result, out ushort?actualCloseCode)
 {
     if (payload.Length == 0)
     {
         // Empty payload is OK
         actualCloseCode = null;
         result          = new WebSocketCloseResult(WebSocketCloseStatus.Empty, string.Empty);
         return(true);
     }
     else if (payload.Length < 2)
     {
         actualCloseCode = null;
         result          = default(WebSocketCloseResult);
         return(false);
     }
     else
     {
         var status = payload.ReadBigEndian <ushort>();
         actualCloseCode = status;
         var description = string.Empty;
         payload = payload.Slice(2);
         if (payload.Length > 0)
         {
             description = payload.GetUtf8String();
         }
         result = new WebSocketCloseResult((WebSocketCloseStatus)status, description);
         return(true);
     }
 }
Beispiel #2
0
        public string GetText()
        {
            if (_text != null)
            {
                return(_text);
            }

            var buffers = this._buffers;

            if (buffers == null)
            {
                if (_buffer.Length == 0)
                {
                    return(_text = "");
                }

                ApplyMask();
                return(_text = _buffer.GetUtf8String());
            }
            return(_text = GetText(buffers));
        }
 public override LinePackageInfo ResolvePackage(ReadableBuffer buffer)
 {
     return(new LinePackageInfo {
         Line = buffer.GetUtf8String()
     });
 }