NebulaGraphEx.Thrift.Client (nebula_graph_ex v0.1.10)

Copy Markdown View Source

Low-level Thrift binary protocol request/response over a framed socket.

This module encodes Thrift CALL messages and decodes REPLY messages using the binary protocol. It is intentionally ignorant of business logic — NebulaGraphEx.Thrift.GraphService builds on this to provide typed calls.

Thrift binary message layout (inside the frame)

<< 0x80, 0x01,        :: 2 bytes   version + message type (CALL = 1)
   0x00, 0x00,        :: 2 bytes   unused (version high bits)
   name_len::32-big,  :: 4 bytes   method name length
   name::binary,      :: N bytes   method name
   seq_id::32-big,    :: 4 bytes   sequence number
   ...struct fields   :: variable  Thrift struct encoding
   0x00 >>            :: 1 byte    STOP field

Replies mirror this layout but with message type REPLY (2) or EXCEPTION (3).

Summary

Functions

Encodes a length-prefixed binary / string.

Encodes a bool.

Encodes a byte.

Encodes and sends a Thrift CALL message, then receives and decodes the REPLY.

Sends a one-way Thrift CALL (no reply expected, e.g. signout).

Decodes a bool.

Decodes a byte.

Decodes a double.

Decodes an i16.

Decodes an i32.

Decodes an i64.

Decodes a length-prefixed binary/string.

Encodes a double.

Encodes a Thrift binary message header + body.

Encodes a field header (type byte + field id).

Encodes an i16.

Encodes an i32.

Encodes an i64.

Encodes a list field (etype, count, then elements).

Encodes a map field (ktype, vtype, count, then pairs).

Skips field headers and returns {field_id, type, rest}.

Encodes the STOP byte that terminates a struct.

Functions

binary_val(v)

Encodes a length-prefixed binary / string.

bool(bool)

Encodes a bool.

byte_val(v)

Encodes a byte.

call(socket, method, args_iodata, seq_id \\ 1, recv_timeout \\ 15000)

@spec call(NebulaGraphEx.Transport.socket(), binary(), iodata(), integer(), timeout()) ::
  {:ok, binary()} | {:error, term()}

Encodes and sends a Thrift CALL message, then receives and decodes the REPLY.

  • socket — a socket returned by NebulaGraphEx.Transport.connect/3
  • method — binary method name, e.g. "execute"
  • args_iodata — already-encoded struct fields (from encode_struct/1)
  • seq_id — sequence number (any integer; 1 is fine for sequential use)
  • recv_timeout — milliseconds to wait for the reply frame

Returns {:ok, reply_payload} where reply_payload is the raw bytes of the reply message body (after the message header), or {:error, reason}.

cast(socket, method, args_iodata, seq_id \\ 1)

@spec cast(NebulaGraphEx.Transport.socket(), binary(), iodata(), integer()) ::
  :ok | {:error, term()}

Sends a one-way Thrift CALL (no reply expected, e.g. signout).

decode_bool(data)

Decodes a bool.

decode_byte(data)

Decodes a byte.

decode_double(data)

Decodes a double.

decode_i16(data)

Decodes an i16.

decode_i32(data)

Decodes an i32.

decode_i64(data)

Decodes an i64.

decode_string(data)

Decodes a length-prefixed binary/string.

double(v)

Encodes a double.

encode_message(method, msg_type, seq_id, body)

Encodes a Thrift binary message header + body.

field(type, id)

Encodes a field header (type byte + field id).

i16(v)

Encodes an i16.

i32(v)

Encodes an i32.

i64(v)

Encodes an i64.

list(etype, items)

Encodes a list field (etype, count, then elements).

map(ktype, vtype, items)

Encodes a map field (ktype, vtype, count, then pairs).

msg_call()

msg_exception()

msg_reply()

next_field(arg)

Skips field headers and returns {field_id, type, rest}.

stop()

Encodes the STOP byte that terminates a struct.

type_binary()

type_bool()

type_byte()

type_double()

type_i16()

type_i32()

type_i64()

type_list()

type_map()

type_set()

type_stop()

type_struct()