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
12pub fn encode_request_fa(
13 ctx: &mut Context,
14 buf: &mut BytesMut,
15 req: &RequestFA,
16) -> Result<DispatchId, EncodeError> {
17 const VERSION: i32 = 1;
18
19 buf.push_int(REQ_FA);
20 buf.push_int(VERSION);
21 buf.push_int(req.fa_data_type);
22
23 Ok(DispatchId::Global(OPCODE_REQUEST_FA))
24}
25
26pub fn encode_replace_fa(
27 ctx: &mut Context,
28 buf: &mut BytesMut,
29 req: &ReplaceFA,
30) -> Result<DispatchId, EncodeError> {
31 const VERSION: i32 = 1;
32
33 buf.push_int(REPLACE_FA);
34 buf.push_int(VERSION);
35 buf.push_int(req.fa_data_type);
36 buf.push_string(&req.xml);
37
38 Ok(DispatchId::Global(OPCODE_REPLACE_FA))
39}
40
41pub fn decode_receive_fa_msg(ctx: &mut Context, buf: &mut BytesMut) -> Result<(Response, i32), io::Error> {
43 let _version = buf.read_int()?;
44 let fa_data_type = buf.read_int()?;
45 let xml = buf.read_string()?;
46
47 Ok((
48 Response::ReceiveFaMsg(ReceiveFaMsg { fa_data_type, xml }),
49 OPCODE_REQUEST_FA,
50 ))
51}