Skip to content

custom {de,}serialization #53

@phi-gamma

Description

@phi-gamma

AFAICS the generator will always define a native Rust struct and offload the
derivation of Deserialize and Serialize to Serde. Often it would be
convenient if custom serialization could be made to work for Varlink types. The
motivation is mainly to prevent extra copies / conversions when working with
FFI.

IOW currently the path between JSON and opaque FFI type is JSON ←→ Rust struct
←→ FFI struct
; ideally it would be just JSON ←→ FFI struct.

Say I have an interface

interface bar.foo
type Foo (
    one: string,
    two: int
)
method GetFoo() -> (foo: Foo)

Varlink will define a struct Foo containing those fields and a trait
Call_GetFoo that handles such a struct. Now I’m actually converting the
struct directly into some opaque FFI type:

#[repr(C)] pub struct FFI_FOO { _private: [u8; 0], }

discarding the Rust struct immediately after.

I’m looking for a way of hooking into the varlink generator so it defines an
alternative to Call_GetFoo that instead uses the newtype FFI_FOO_PTR:

struct FFI_FOO_PTR (*mut FFI_FOO);

which has implementations for Deserialize and Serialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions