public static byte[] ReadLongstr(NetworkBinaryReader reader)
 {
     uint byteCount = reader.ReadUInt32();
     if (byteCount > int.MaxValue)
     {
         throw new SyntaxError("Long string too long; " +
                               "byte length=" + byteCount + ", max=" + int.MaxValue);
     }
     return reader.ReadBytes((int)byteCount);
 }
Esempio n. 2
0
        public static Frame ReadFrom(NetworkBinaryReader reader)
        {
            int type;
            int channel;

            try
            {
                type = reader.ReadByte();
            }
            catch (IOException ioe)
            {
                // If it's a WSAETIMEDOUT SocketException, unwrap it.
                // This might happen when the limit of half-open connections is
                // reached.
                if (ioe.InnerException == null ||
                    !(ioe.InnerException is SocketException) ||
                    ((SocketException)ioe.InnerException).SocketErrorCode != SocketError.TimedOut)
                    throw ioe;
                throw ioe.InnerException;
            }

            if (type == 'A')
            {
                // Probably an AMQP protocol header, otherwise meaningless
                ProcessProtocolHeader(reader);
            }

            channel = reader.ReadUInt16();
            int payloadSize = reader.ReadInt32(); // FIXME - throw exn on unreasonable value
            byte[] payload = reader.ReadBytes(payloadSize);
            if (payload.Length != payloadSize)
            {
                // Early EOF.
                throw new MalformedFrameException("Short frame - expected " +
                                                  payloadSize + " bytes, got " +
                                                  payload.Length + " bytes");
            }

            int frameEndMarker = reader.ReadByte();
            if (frameEndMarker != CommonFraming.Constants.FrameEnd)
            {
                throw new MalformedFrameException("Bad frame end marker: " + frameEndMarker);
            }

            return new Frame(type, channel, payload);
        }
Esempio n. 3
0
        public static Frame ReadFrom(NetworkBinaryReader reader)
        {
            int type;
            int channel;

            type = reader.ReadByte();

            if (type == 'A')
            {
                // Probably an AMQP protocol header, otherwise meaningless
                ProcessProtocolHeader(reader);
            }

            channel = reader.ReadUInt16();
            int payloadSize = reader.ReadInt32(); // FIXME - throw exn on unreasonable value
            byte[] payload = reader.ReadBytes(payloadSize);
            if (payload.Length != payloadSize)
            {
                // Early EOF.
                throw new MalformedFrameException("Short frame - expected " +
                                                  payloadSize + " bytes, got " +
                                                  payload.Length + " bytes");
            }

            int frameEndMarker = reader.ReadByte();
            if (frameEndMarker != CommonFraming.Constants.FrameEnd)
            {
                throw new MalformedFrameException("Bad frame end marker: " + frameEndMarker);
            }

            return new Frame(type, channel, payload);
        }
 public static string ReadShortstr(NetworkBinaryReader reader)
 {
     int byteCount = reader.ReadByte();
     return Encoding.UTF8.GetString(reader.ReadBytes(byteCount));
 }
        ///<exception cref="EndOfStreamException"/>
        ///<exception cref="ProtocolViolationException"/>
        public static object ReadObject(NetworkBinaryReader reader) {
            int typeTag = reader.ReadByte();
            switch (typeTag) {
	      case -1:
		  throw new EndOfStreamException("End of StreamMessage reached");

              case (int) StreamWireFormattingTag.Bool: {
                  byte value = reader.ReadByte();
                  switch (value) {
                    case 0x00: return false;
                    case 0x01: return true;
                    default: {
                        string message =
                            string.Format("Invalid boolean value in StreamMessage: {0}", value);
                        throw new ProtocolViolationException(message);
                    }
                  }
              }

              case (int) StreamWireFormattingTag.Byte:
                  return reader.ReadByte();

              case (int) StreamWireFormattingTag.Bytes: {
                  int length = reader.ReadInt32();
                  if (length == -1) {
                      return null;
                  } else {
                      return reader.ReadBytes(length);
                  }
              }

              case (int) StreamWireFormattingTag.Int16:
                  return reader.ReadInt16();

              case (int) StreamWireFormattingTag.Char:
                  return (char) reader.ReadUInt16();

              case (int) StreamWireFormattingTag.Int32:
                  return reader.ReadInt32();

              case (int) StreamWireFormattingTag.Int64:
                  return reader.ReadInt64();

              case (int) StreamWireFormattingTag.Single:
                  return reader.ReadSingle();

              case (int) StreamWireFormattingTag.Double:
                  return reader.ReadDouble();

              case (int) StreamWireFormattingTag.String:
                  return ReadUntypedString(reader);

              case (int) StreamWireFormattingTag.Null:
                  return null;

              default: {
                  string message = string.Format("Invalid type tag in StreamMessage: {0}",
                                                 typeTag);
                  throw new ProtocolViolationException(message);
              }
            }
        }
 public static string ReadString(NetworkBinaryReader reader)
 {
     ushort length = reader.ReadUInt16();
     byte[] bytes = reader.ReadBytes(length);
     return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
 }
 public static byte[] ReadBytes(NetworkBinaryReader reader, int count)
 {
     return reader.ReadBytes(count);
 }