JsonrpcOutputStream

JsonrpcOutputStream — A JSON-RPC output stream

Functions

Properties

gboolean use-gvariant Read / Write

Types and Values

Object Hierarchy

    GObject
    ╰── GOutputStream
        ╰── GFilterOutputStream
            ╰── GDataOutputStream
                ╰── JsonrpcOutputStream

Implemented Interfaces

JsonrpcOutputStream implements GSeekable.

Description

The JsonrpcOutputStream is resonsible for serializing messages onto the underlying stream.

Optionally, if jsonrpc_output_stream_set_use_gvariant() has been called, the messages will be encoded directly in the GVariant format instead of JSON along with setting a "Content-Type" header to "application/gvariant". This is useful for situations where you control both sides of the RPC server using jsonrpc-glib as you can reduce the overhead of parsing JSON nodes due to GVariant not requiring parsing or allocation overhead to the same degree as JSON.

For example, if you need a large message, which is encoded in JSON, you need to decode the entire message up front which avoids performing lazy operations. When using GVariant encoding, you have a single allocation created for the GVariant which means you reduce the memory pressure caused by lots of small allocations.

Functions

jsonrpc_output_stream_new ()

JsonrpcOutputStream *
jsonrpc_output_stream_new (GOutputStream *base_stream);

jsonrpc_output_stream_get_use_gvariant ()

gboolean
jsonrpc_output_stream_get_use_gvariant
                               (JsonrpcOutputStream *self);

jsonrpc_output_stream_set_use_gvariant ()

void
jsonrpc_output_stream_set_use_gvariant
                               (JsonrpcOutputStream *self,
                                gboolean use_gvariant);

jsonrpc_output_stream_write_message ()

gboolean
jsonrpc_output_stream_write_message (JsonrpcOutputStream *self,
                                     GVariant *message,
                                     GCancellable *cancellable,
                                     GError **error);

Synchronously sends a message to the peer.

This operation will complete once the message has been buffered. There is no guarantee the peer received it.

Parameters

self

a JsonrpcOutputStream

 

message

a GVariant.

[transfer none]

cancellable

a GCancellable or NULL.

[nullable]

error

a location for a GError, or NULL

 

Since: 3.26

jsonrpc_output_stream_write_message_async ()

void
jsonrpc_output_stream_write_message_async
                               (JsonrpcOutputStream *self,
                                GVariant *message,
                                GCancellable *cancellable,
                                GAsyncReadyCallback callback,
                                gpointer user_data);

Asynchronously sends a message to the peer.

This asynchronous operation will complete once the message has been buffered, and there is no guarantee the peer received it.

Parameters

self

a JsonrpcOutputStream

 

message

a GVariant.

[transfer none]

cancellable

a GCancellable or NULL.

[nullable]

callback

a GAsyncReadyCallback or NULL.

[nullable]

user_data

closure data for callback

 

Since: 3.26

jsonrpc_output_stream_write_message_finish ()

gboolean
jsonrpc_output_stream_write_message_finish
                               (JsonrpcOutputStream *self,
                                GAsyncResult *result,
                                GError **error);

Types and Values

JSONRPC_TYPE_OUTPUT_STREAM

#define JSONRPC_TYPE_OUTPUT_STREAM (jsonrpc_output_stream_get_type())

struct JsonrpcOutputStreamClass

struct JsonrpcOutputStreamClass {
  GDataOutputStreamClass parent_class;

  gpointer _reserved1;
  gpointer _reserved2;
  gpointer _reserved3;
  gpointer _reserved4;
  gpointer _reserved5;
  gpointer _reserved6;
  gpointer _reserved7;
  gpointer _reserved8;
  gpointer _reserved9;
  gpointer _reserved10;
  gpointer _reserved11;
  gpointer _reserved12;
};

JsonrpcOutputStream

typedef struct _JsonrpcOutputStream JsonrpcOutputStream;

Property Details

The “use-gvariant” property

  “use-gvariant”             gboolean

If GVariant encoding should be used.

Owner: JsonrpcOutputStream

Flags: Read / Write

Default value: FALSE