Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

No support for flattened arrays in structs #10

Open
arnsholt opened this Issue · 1 comment

2 participants

@arnsholt
Collaborator

We need to support flattened arrays in structs. For example a ZMQ message has the following definition:

typedef struct
{
    void *content;
    unsigned char flags;
    unsigned char vsm_size;
    unsigned char vsm_data [ZMQ_MAX_VSM_SIZE];
} zmq_msg_t;

To first order, that implies a class like this, if it weren't for the fact that the CArray[type] syntax is already taken for type *:

class ZMQ::Message is repr('CStruct') {
    OpaquePointer $!content;
    int8 $!flags;
    int8 $!vsm_size;
    CArray[int8] $!vsm_data;
}

AFAICT, there are a few different parts to this problem. The first is which syntax to use for flattened arrays. Something like CArray[int8] $!vsm_data is flattened(30) might work, but I'm not sure exactly how that would operate under the hood.

Another issue is the fact that these arrays (at least if masquerading as CArrays) are inherently read-only in the sense that $!vsm_data := $other_carray really isn't possible. We might be able to fake it via copying or something, but I think the user-facing API should make it as clear as possible that the identity of the array itself is immutable (even though the actual pieces of data pointed at are mutable).

The lack of this is work-aroundable by embedding the appropriate number of things in a row in the class definition and some clever accessor stuff, but I don't think that's a tenable approach long term.

@arnsholt
Collaborator

As moritz points out, Buf would be a natural type for representing flattened arrays.

@FROGGS FROGGS added the Feature label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.