1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright 2020 UT OVERSEAS INC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use lazy_static::lazy_static;

use crate::offset_of;
use crate::utils::types::Index;

#[repr(C, packed(4))]
#[derive(Copy, Clone)]
pub struct DataFrameHeaderDefn {
    pub frame_length: i32,
    pub version: u8,
    pub flags: u8,
    pub frame_type: u16,
    pub term_offset: i32,
    pub session_id: i32,
    pub stream_id: i32,
    pub term_id: i32,
    pub reserved_value: i64,
}

lazy_static! {
    pub static ref FRAME_LENGTH_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, frame_length);
    pub static ref VERSION_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, version);
    pub static ref FLAGS_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, flags);
    pub static ref TYPE_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, frame_type);
    pub static ref TERM_OFFSET_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, term_offset);
    pub static ref SESSION_ID_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, session_id);
    pub static ref STREAM_ID_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, stream_id);
    pub static ref TERM_ID_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, term_id);
    pub static ref RESERVED_VALUE_FIELD_OFFSET: Index = offset_of!(DataFrameHeaderDefn, reserved_value);
}

pub const DATA_OFFSET: Index = std::mem::size_of::<DataFrameHeaderDefn>() as Index;
pub const LENGTH: Index = DATA_OFFSET;

pub const HDR_TYPE_PAD: u16 = 0x00;
pub const HDR_TYPE_DATA: u16 = 0x01;
pub const HDR_TYPE_NAK: u16 = 0x02;
pub const HDR_TYPE_SM: u16 = 0x03;
pub const HDR_TYPE_ERR: u16 = 0x04;
pub const HDR_TYPE_SETUP: u16 = 0x05;
pub const HDR_TYPE_EXT: u16 = 0xFFFF;

pub const CURRENT_VERSION: u8 = 0x0;