/// <summary> /// Creates a new instance of the frame builder to handle parsing of incoming byte stream. /// </summary> /// <param name="config">Socket configurations for this session.</param> public MqFrameBuilder(MqConfig config) { _config = config; _internalBuffer = new byte[config.FrameBufferSize + MqFrame.HeaderLength]; // Determine what our max enum value is for the FrameType if (_maxTypeEnum == -1) { _maxTypeEnum = Enum.GetValues(typeof(MqFrameType)).Cast <byte>().Max(); } _bufferStream = new MemoryStream(_internalBuffer, 0, _internalBuffer.Length, true, true); }
/// <summary> /// Creates a new frame wit the specified bytes and configurations. /// </summary> /// <param name="bytes">Byte buffer to use for this frame.</param> /// <param name="type">Initial type of frame to create.</param> /// <param name="config">Socket configurations used for creating and finalizing this frame.</param> public MqFrame(byte[] bytes, MqFrameType type, MqConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config), "Configurations can not be null."); } _config = config; if (bytes?.Length > _config.FrameBufferSize) { throw new ArgumentException( "Byte array passed is larger than the maximum frame size allowed. Must be less than " + config.FrameBufferSize, nameof(bytes)); } _buffer = bytes; FrameType = type; }
/// <summary> /// Creates a new message writer with the specified socket configurations and encoding. /// </summary> /// <param name="config">Current socket configurations. Used to create new frames.</param> /// <param name="encoding">Encoding to use for string and char parsing.</param> public MqMessageWriter(MqConfig config, Encoding encoding) { _config = config; _encoding = encoding; _builderFrame = new MqFrame(new byte[config.FrameBufferSize], MqFrameType.More, config); }
/// <summary> /// Creates a new frame wit the specified bytes and configurations. /// </summary> /// <param name="bytes">Byte buffer to use for this frame.</param> /// <param name="config">Socket configurations used for creating and finalizing this frame.</param> public MqFrame(byte[] bytes, MqConfig config) : this(bytes, MqFrameType.Unset, config) { }
/// <summary> /// Creates a new message writer with the specified socket configurations default UTF8 encoding. /// </summary> /// <param name="config">Current socket configurations. Used to create new frames.</param> public MqMessageWriter(MqConfig config) : this(config, Encoding.UTF8) { }