Skip to content

Commit c30a961

Browse files
authored
Merge pull request #2288 from sphaero/zosc_fromstring
Create an OSC message from a string
2 parents f7f7649 + eb9003d commit c30a961

File tree

19 files changed

+357
-13
lines changed

19 files changed

+357
-13
lines changed

api/python_cffi.slurp

+9
Original file line numberDiff line numberDiff line change
@@ -4647,6 +4647,11 @@ zosc_t *
46474647
zosc_t *
46484648
zosc_frommem (char *data, size_t size);
46494649

4650+
// Create a new zosc message from a string. This the same syntax as
4651+
// zosc_create but written as a single line string.
4652+
zosc_t *
4653+
zosc_fromstring (const char *oscstring);
4654+
46504655
// Create a new zosc message from the given format and arguments.
46514656
// The format type tags are as follows:
46524657
// i - 32bit integer
@@ -4750,6 +4755,10 @@ zframe_t *
47504755
zosc_t *
47514756
zosc_unpack (zframe_t *frame);
47524757

4758+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
4759+
char *
4760+
zosc_dump (zosc_t *self);
4761+
47534762
// Dump OSC message to stdout, for debugging and tracing.
47544763
void
47554764
zosc_print (zosc_t *self);

api/zosc.api

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<argument name = "size" type = "size" />
5050
</constructor>
5151

52+
<constructor name = "fromstring" state = "draft">
53+
Create a new zosc message from a string. This the same syntax as
54+
zosc_create but written as a single line string.
55+
<argument name = "oscstring" type = "string" />
56+
</constructor>
57+
5258
<constructor name = "create">
5359
Create a new zosc message from the given format and arguments.
5460
The format type tags are as follows:
@@ -168,6 +174,11 @@
168174
<return type = "zosc" fresh = "1" />
169175
</method>
170176

177+
<method name = "dump">
178+
Return a string describing the the OSC message. The returned string must be freed by the caller.
179+
<return type = "string" fresh="1" />
180+
</method>
181+
171182
<method name = "print">
172183
Dump OSC message to stdout, for debugging and tracing.
173184
</method>

bindings/jni/czmq-jni/src/main/c/org_zeromq_czmq_Zosc.c

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Java_org_zeromq_czmq_Zosc__1_1frommem (JNIEnv *env, jclass c, jbyteArray data, j
3737
return frommem_;
3838
}
3939

40+
JNIEXPORT jlong JNICALL
41+
Java_org_zeromq_czmq_Zosc__1_1fromstring (JNIEnv *env, jclass c, jstring oscstring)
42+
{
43+
char *oscstring_ = (char *) (*env)->GetStringUTFChars (env, oscstring, NULL);
44+
jlong fromstring_ = (jlong) (intptr_t) zosc_fromstring (oscstring_);
45+
(*env)->ReleaseStringUTFChars (env, oscstring, oscstring_);
46+
return fromstring_;
47+
}
48+
4049
JNIEXPORT jlong JNICALL
4150
Java_org_zeromq_czmq_Zosc__1_1create (JNIEnv *env, jclass c, jstring address, jstring format)
4251
{
@@ -133,6 +142,15 @@ Java_org_zeromq_czmq_Zosc__1_1unpack (JNIEnv *env, jclass c, jlong frame)
133142
return unpack_;
134143
}
135144

145+
JNIEXPORT jstring JNICALL
146+
Java_org_zeromq_czmq_Zosc__1_1dump (JNIEnv *env, jclass c, jlong self)
147+
{
148+
char *dump_ = (char *) zosc_dump ((zosc_t *) (intptr_t) self);
149+
jstring return_string_ = (*env)->NewStringUTF (env, dump_);
150+
zstr_free (&dump_);
151+
return return_string_;
152+
}
153+
136154
JNIEXPORT void JNICALL
137155
Java_org_zeromq_czmq_Zosc__1_1print (JNIEnv *env, jclass c, jlong self)
138156
{

bindings/jni/czmq-jni/src/main/java/org/zeromq/czmq/Zosc.java

+15
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public static Zosc frommem (byte [] data, long size) {
5454
return new Zosc (__frommem (data, size));
5555
}
5656
/*
57+
Create a new zosc message from a string. This the same syntax as
58+
zosc_create but written as a single line string.
59+
*/
60+
native static long __fromstring (String oscstring);
61+
public static Zosc fromstring (String oscstring) {
62+
return new Zosc (__fromstring (oscstring));
63+
}
64+
/*
5765
Create a new zosc message from the given format and arguments.
5866
The format type tags are as follows:
5967
i - 32bit integer
@@ -195,6 +203,13 @@ public static Zosc unpack (Zframe frame) {
195203
return new Zosc (__unpack (frame.self));
196204
}
197205
/*
206+
Return a string describing the the OSC message. The returned string must be freed by the caller.
207+
*/
208+
native static String __dump (long self);
209+
public String dump () {
210+
return __dump (self);
211+
}
212+
/*
198213
Dump OSC message to stdout, for debugging and tracing.
199214
*/
200215
native static void __print (long self);

bindings/lua_ffi/czmq_ffi.lua

+9
Original file line numberDiff line numberDiff line change
@@ -4642,6 +4642,11 @@ zosc_t *
46424642
zosc_t *
46434643
zosc_frommem (char *data, size_t size);
46444644

4645+
// Create a new zosc message from a string. This the same syntax as
4646+
// zosc_create but written as a single line string.
4647+
zosc_t *
4648+
zosc_fromstring (const char *oscstring);
4649+
46454650
// Create a new zosc message from the given format and arguments.
46464651
// The format type tags are as follows:
46474652
// i - 32bit integer
@@ -4745,6 +4750,10 @@ zframe_t *
47454750
zosc_t *
47464751
zosc_unpack (zframe_t *frame);
47474752

4753+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
4754+
char *
4755+
zosc_dump (zosc_t *self);
4756+
47484757
// Dump OSC message to stdout, for debugging and tracing.
47494758
void
47504759
zosc_print (zosc_t *self);

bindings/nodejs/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -5208,6 +5208,12 @@ zosc my_zosc.unpack (Zframe)
52085208

52095209
Transform a zframe into a zosc.
52105210

5211+
```
5212+
string my_zosc.dump ()
5213+
```
5214+
5215+
Return a string describing the the OSC message. The returned string must be freed by the caller.
5216+
52115217
```
52125218
nothing my_zosc.print ()
52135219
```

bindings/nodejs/binding.cc

+7
Original file line numberDiff line numberDiff line change
@@ -9679,6 +9679,7 @@ NAN_MODULE_INIT (Zosc::Init) {
96799679
Nan::SetPrototypeMethod (tpl, "pack", _pack);
96809680
Nan::SetPrototypeMethod (tpl, "packx", _packx);
96819681
Nan::SetPrototypeMethod (tpl, "unpack", _unpack);
9682+
Nan::SetPrototypeMethod (tpl, "dump", _dump);
96829683
Nan::SetPrototypeMethod (tpl, "print", _print);
96839684
Nan::SetPrototypeMethod (tpl, "popInt32", _pop_int32);
96849685
Nan::SetPrototypeMethod (tpl, "popInt64", _pop_int64);
@@ -9840,6 +9841,12 @@ NAN_METHOD (Zosc::_unpack) {
98409841
}
98419842
}
98429843

9844+
NAN_METHOD (Zosc::_dump) {
9845+
Zosc *zosc = Nan::ObjectWrap::Unwrap <Zosc> (info.Holder ());
9846+
char *result = (char *) zosc_dump (zosc->self);
9847+
info.GetReturnValue ().Set (Nan::New (result).ToLocalChecked ());
9848+
}
9849+
98439850
NAN_METHOD (Zosc::_print) {
98449851
Zosc *zosc = Nan::ObjectWrap::Unwrap <Zosc> (info.Holder ());
98459852
zosc_print (zosc->self);

bindings/nodejs/binding.h

+1
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ class Zosc: public Nan::ObjectWrap {
11301130
static NAN_METHOD (_pack);
11311131
static NAN_METHOD (_packx);
11321132
static NAN_METHOD (_unpack);
1133+
static NAN_METHOD (_dump);
11331134
static NAN_METHOD (_print);
11341135
static NAN_METHOD (_pop_int32);
11351136
static NAN_METHOD (_pop_int64);

bindings/python/czmq/_czmq_ctypes.py

+18
Original file line numberDiff line numberDiff line change
@@ -9559,6 +9559,8 @@ def test(verbose):
95599559
lib.zosc_fromframe.argtypes = [zframe_p]
95609560
lib.zosc_frommem.restype = zosc_p
95619561
lib.zosc_frommem.argtypes = [c_void_p, c_size_t]
9562+
lib.zosc_fromstring.restype = zosc_p
9563+
lib.zosc_fromstring.argtypes = [c_char_p]
95629564
lib.zosc_create.restype = zosc_p
95639565
lib.zosc_create.argtypes = [c_char_p, c_char_p]
95649566
lib.zosc_size.restype = c_size_t
@@ -9581,6 +9583,8 @@ def test(verbose):
95819583
lib.zosc_packx.argtypes = [POINTER(zosc_p)]
95829584
lib.zosc_unpack.restype = zosc_p
95839585
lib.zosc_unpack.argtypes = [zframe_p]
9586+
lib.zosc_dump.restype = POINTER(c_char)
9587+
lib.zosc_dump.argtypes = [zosc_p]
95849588
lib.zosc_print.restype = None
95859589
lib.zosc_print.argtypes = [zosc_p]
95869590
lib.zosc_is.restype = c_bool
@@ -9695,6 +9699,14 @@ def frommem(data, size):
96959699
"""
96969700
return Zosc(lib.zosc_frommem(data, size), True)
96979701

9702+
@staticmethod
9703+
def fromstring(oscstring):
9704+
"""
9705+
Create a new zosc message from a string. This the same syntax as
9706+
zosc_create but written as a single line string.
9707+
"""
9708+
return Zosc(lib.zosc_fromstring(oscstring), True)
9709+
96989710
@staticmethod
96999711
def create(address, format, *args):
97009712
"""
@@ -9819,6 +9831,12 @@ def unpack(frame):
98199831
"""
98209832
return Zosc(lib.zosc_unpack(frame), True)
98219833

9834+
def dump(self):
9835+
"""
9836+
Return a string describing the the OSC message. The returned string must be freed by the caller.
9837+
"""
9838+
return return_fresh_string(lib.zosc_dump(self._as_parameter_))
9839+
98229840
def print(self):
98239841
"""
98249842
Dump OSC message to stdout, for debugging and tracing.

bindings/python_cffi/czmq_cffi/Zosc.py

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def frommem(data, size):
6161
"""
6262
return utils.lib.zosc_frommem(data, size)
6363

64+
@staticmethod
65+
def fromstring(oscstring):
66+
"""
67+
Create a new zosc message from a string. This the same syntax as
68+
zosc_create but written as a single line string.
69+
"""
70+
return utils.lib.zosc_fromstring(utils.to_bytes(oscstring))
71+
6472
@staticmethod
6573
def create(address, format, *format_args):
6674
"""
@@ -185,6 +193,12 @@ def unpack(frame):
185193
"""
186194
return utils.lib.zosc_unpack(frame._p)
187195

196+
def dump(self):
197+
"""
198+
Return a string describing the the OSC message. The returned string must be freed by the caller.
199+
"""
200+
return utils.lib.zosc_dump(self._p)
201+
188202
def print_py(self):
189203
"""
190204
Dump OSC message to stdout, for debugging and tracing.

bindings/python_cffi/czmq_cffi/cdefs.py

+9
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,11 @@
46494649
zosc_t *
46504650
zosc_frommem (char *data, size_t size);
46514651
4652+
// Create a new zosc message from a string. This the same syntax as
4653+
// zosc_create but written as a single line string.
4654+
zosc_t *
4655+
zosc_fromstring (const char *oscstring);
4656+
46524657
// Create a new zosc message from the given format and arguments.
46534658
// The format type tags are as follows:
46544659
// i - 32bit integer
@@ -4752,6 +4757,10 @@
47524757
zosc_t *
47534758
zosc_unpack (zframe_t *frame);
47544759
4760+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
4761+
char *
4762+
zosc_dump (zosc_t *self);
4763+
47554764
// Dump OSC message to stdout, for debugging and tracing.
47564765
void
47574766
zosc_print (zosc_t *self);

bindings/qml/src/QmlZosc.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ QmlZframe *QmlZosc::pack () {
9999
return retQ_;
100100
};
101101

102+
///
103+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
104+
QString QmlZosc::dump () {
105+
char *retStr_ = zosc_dump (self);
106+
QString retQStr_ = QString (retStr_);
107+
free (retStr_);
108+
return retQStr_;
109+
};
110+
102111
///
103112
// Dump OSC message to stdout, for debugging and tracing.
104113
void QmlZosc::print () {
@@ -254,6 +263,15 @@ QmlZosc *QmlZoscAttached::frommem (char *data, size_t size) {
254263
return qmlSelf;
255264
};
256265

266+
///
267+
// Create a new zosc message from a string. This the same syntax as
268+
// zosc_create but written as a single line string.
269+
QmlZosc *QmlZoscAttached::fromstring (const QString &oscstring) {
270+
QmlZosc *qmlSelf = new QmlZosc ();
271+
qmlSelf->self = zosc_fromstring (oscstring.toUtf8().data());
272+
return qmlSelf;
273+
};
274+
257275
///
258276
// Create a new zosc message from the given format and arguments.
259277
// The format type tags are as follows:

bindings/qml/src/QmlZosc.h

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public slots:
9191
// Transform zosc into a zframe that can be sent in a message.
9292
QmlZframe *pack ();
9393

94+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
95+
QString dump ();
96+
9497
// Dump OSC message to stdout, for debugging and tracing.
9598
void print ();
9699

@@ -185,6 +188,10 @@ public slots:
185188
// and calling free on the data after construction.
186189
QmlZosc *frommem (char *data, size_t size);
187190

191+
// Create a new zosc message from a string. This the same syntax as
192+
// zosc_create but written as a single line string.
193+
QmlZosc *fromstring (const QString &oscstring);
194+
188195
// Create a new zosc message from the given format and arguments.
189196
// The format type tags are as follows:
190197
// i - 32bit integer

bindings/qt/src/qzosc.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ QZosc* QZosc::frommem (char *data, size_t size, QObject *qObjParent)
3838
return new QZosc (zosc_frommem (data, size), qObjParent);
3939
}
4040

41+
///
42+
// Create a new zosc message from a string. This the same syntax as
43+
// zosc_create but written as a single line string.
44+
QZosc* QZosc::fromstring (const QString &oscstring, QObject *qObjParent)
45+
{
46+
return new QZosc (zosc_fromstring (oscstring.toUtf8().data()), qObjParent);
47+
}
48+
4149
///
4250
// Destroy an OSC message
4351
QZosc::~QZosc ()
@@ -126,6 +134,16 @@ QZosc * QZosc::unpack (QZframe *frame)
126134
return rv;
127135
}
128136

137+
///
138+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
139+
QString QZosc::dump ()
140+
{
141+
char *retStr_ = zosc_dump (self);
142+
QString rv = QString (retStr_);
143+
zstr_free (&retStr_);
144+
return rv;
145+
}
146+
129147
///
130148
// Dump OSC message to stdout, for debugging and tracing.
131149
void QZosc::print ()

bindings/qt/src/qzosc.h

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class QT_CZMQ_EXPORT QZosc : public QObject
2828
// and calling free on the data after construction.
2929
static QZosc* frommem (char *data, size_t size, QObject *qObjParent = 0);
3030

31+
// Create a new zosc message from a string. This the same syntax as
32+
// zosc_create but written as a single line string.
33+
static QZosc* fromstring (const QString &oscstring, QObject *qObjParent = 0);
34+
3135
// Destroy an OSC message
3236
~QZosc ();
3337

@@ -72,6 +76,9 @@ class QT_CZMQ_EXPORT QZosc : public QObject
7276
// Transform a zframe into a zosc.
7377
static QZosc * unpack (QZframe *frame);
7478

79+
// Return a string describing the the OSC message. The returned string must be freed by the caller.
80+
QString dump ();
81+
7582
// Dump OSC message to stdout, for debugging and tracing.
7683
void print ();
7784

bindings/ruby/lib/czmq/ffi.rb

+2
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ def self.attach_function(name, *rest)
989989
attach_function :zosc_new, [:string], :pointer, **opts
990990
attach_function :zosc_fromframe, [:pointer], :pointer, **opts
991991
attach_function :zosc_frommem, [:pointer, :size_t], :pointer, **opts
992+
attach_function :zosc_fromstring, [:string], :pointer, **opts
992993
attach_function :zosc_create, [:string, :string, :varargs], :pointer, **opts
993994
attach_function :zosc_destroy, [:pointer], :void, **opts
994995
attach_function :zosc_size, [:pointer], :size_t, **opts
@@ -1001,6 +1002,7 @@ def self.attach_function(name, *rest)
10011002
attach_function :zosc_pack, [:pointer], :pointer, **opts
10021003
attach_function :zosc_packx, [:pointer], :pointer, **opts
10031004
attach_function :zosc_unpack, [:pointer], :pointer, **opts
1005+
attach_function :zosc_dump, [:pointer], :pointer, **opts
10041006
attach_function :zosc_print, [:pointer], :void, **opts
10051007
attach_function :zosc_is, [:pointer], :bool, **opts
10061008
attach_function :zosc_first, [:pointer, :pointer], :pointer, **opts

0 commit comments

Comments
 (0)