![]() |
![]() |
![]() |
![]() |
GObject ╰── GOutputStream ╰── GFilterOutputStream ╰── GDataOutputStream ╰── JsonrpcOutputStream
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.
JsonrpcOutputStream *
jsonrpc_output_stream_new (GOutputStream *base_stream
);
gboolean
jsonrpc_output_stream_get_use_gvariant
(JsonrpcOutputStream *self
);
void jsonrpc_output_stream_set_use_gvariant (JsonrpcOutputStream *self
,gboolean use_gvariant
);
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.
self |
||
message |
a GVariant. |
[transfer none] |
cancellable |
a GCancellable or |
[nullable] |
error |
Since: 3.26
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.
self |
||
message |
a GVariant. |
[transfer none] |
cancellable |
a GCancellable or |
[nullable] |
callback |
a GAsyncReadyCallback or |
[nullable] |
user_data |
closure data for |
Since: 3.26
gboolean jsonrpc_output_stream_write_message_finish (JsonrpcOutputStream *self
,GAsyncResult *result
,GError **error
);
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; };
“use-gvariant”
property“use-gvariant” gboolean
If GVariant encoding should be used.
Owner: JsonrpcOutputStream
Flags: Read / Write
Default value: FALSE