///<summary>Fill this instance from the given byte buffer stream.
 ///</summary>
 public ulong ReadFrom(NetworkBinaryReader reader)
 {
     reader.ReadUInt16(); // weight - not currently used
     ulong bodySize = reader.ReadUInt64();
     ReadPropertiesFrom(new ContentHeaderPropertyReader(reader));
     return bodySize;
 }
 ///<summary>Fill this instance from the given byte buffer
 ///stream. Throws BodyTooLongException, which is the reason
 ///for the channelNumber parameter.</summary>
 ///<remarks>
 ///<para>
 /// It might be better to do the body length check in our
 /// caller, currently CommandAssembler, which would avoid
 /// passing in the otherwise unrequired channelNumber
 /// parameter.
 ///</para>
 ///</remarks>
 public ulong ReadFrom(int channelNumber, NetworkBinaryReader reader)
 {
     reader.ReadUInt16(); // weight - not currently used
     ulong bodySize = reader.ReadUInt64();
     if (bodySize > MaximumPermittedReceivableBodySize)
     {
         throw new BodyTooLongException(channelNumber, bodySize);
     }
     ReadPropertiesFrom(new ContentHeaderPropertyReader(reader));
     return bodySize;
 }
Пример #3
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);
        }
Пример #4
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 ushort ReadShort(NetworkBinaryReader reader)
 {
     return reader.ReadUInt16();
 }
        ///<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 char ReadChar(NetworkBinaryReader reader)
 {
     return (char) reader.ReadUInt16();
 }