ib_async/message/
err_msg.rs

1use super::constants::*;
2use super::context::{Context, DispatchId};
3use super::error::EncodeError;
4use super::request::*;
5use super::response::*;
6use super::util::*;
7use super::wire::{TwsWireDecoder, TwsWireEncoder};
8use bytes::{BufMut, BytesMut};
9use domain::*;
10use std::io;
11
12// 	id: the request identifier which generated the error. Note: -1 will indicate a notification and not true error condition.
13// error_code: 	the code identifying the error.
14// error_message: error's description.
15pub fn decode_err_msg(ctx: &mut Context, buf: &mut BytesMut) -> Result<(Response, i32), io::Error> {
16    let version = buf.read_int()?;
17    if version < 2 {
18        let msg = buf.read_string()?;
19        Ok((
20            Response::ErrMsgMsg(ErrMsgMsg {
21                id: -1,
22                error_code: -1,
23                error_message: msg,
24            }),
25            -1,
26        ))
27    } else {
28        let id = buf.read_int()?;
29        let error_code = buf.read_int()?;
30        let error_message = buf.read_string()?;
31        Ok((
32            Response::ErrMsgMsg(ErrMsgMsg {
33                id,
34                error_code,
35                error_message,
36            }),
37            OPCODE_ERR,
38        ))
39    }
40}