poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] mi-frame.pk


From: Mohammad-Reza Nabipoor
Subject: [RFC] mi-frame.pk
Date: Sat, 27 Nov 2021 01:56:22 +0330

Hi Jose and others,

Do you agree with this schema for MI messages (messages between a client
and GNU poke)?


```poke
set_endian (ENDIAN_BIG);

var MI_LENGTH_MAX = 2048#B;

var MI_FRAME_TYPE_JSON = 0 as uint<5>,
    MI_FRAME_TYPE_RAW  = 1 as uint<5>;

type MI_Frame_Info = struct byte
  {
    uint<3> version = 0; /* We should be ready for possible changes! */
    uint<5> frame_type : frame_type in [MI_FRAME_TYPE_JSON, MI_FRAME_TYPE_RAW];
  };

type MI_Frame = struct
  {
    offset<uint16,B> size : size <= MI_LENGTH_MAX;
    MI_Frame_Info info;
    uint32 seq_no;
    byte[size] payload;
  };

/* Examples */

fun json_to_bytes = (string json) byte[]:
  {
    var bytes = byte[json'size] ();

    stoca (json, bytes);
    return bytes;
  }

var json_1 = json_to_bytes 
("{\"value\":-3500,\"type\":{\"code\":\"Integral\",\"info\":{\"size\":32,\"signed_p\":true}}}\n");
var frm_1 = MI_Frame
  {
    size = json_1'size,
    info = MI_Frame_Info { frame_type = MI_FRAME_TYPE_JSON },
    seq_no = 1,
    payload = json_1,
  };

var raw_1 = byte[MI_LENGTH_MAX] (0xff);
var frm_2 = MI_Frame
  {
    size = raw_1'size,
    info = MI_Frame_Info { frame_type = MI_FRAME_TYPE_RAW },
    seq_no = 5,
    payload = raw_1,
  };
```


Regards,
Mohammad-Reza



reply via email to

[Prev in Thread] Current Thread [Next in Thread]