-
Notifications
You must be signed in to change notification settings - Fork 49
/
OSCEncoder.cpp
68 lines (36 loc) · 1.41 KB
/
OSCEncoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
ArdOSC 2.1 - OSC Library for Arduino.
-------- Lisence -----------------------------------------------------------
ArdOSC
The MIT License
Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved
*/
#include <stdlib.h>
#include <string.h>
#include "OSCcommon/OSCcommon.h"
#include "OSCCommon/OSCEncoder.h"
#include "OSCCommon/OSCArg.h"
int16_t OSCEncoder::encode( OSCMessage::OSCMessage *_newMes ,uint8_t *_binData ){
uint8_t *packStartPtr = _binData;
//=========== OSC Address(String) -> BIN Encode ===========
memcpy( _binData , _newMes->_oscAddress , _newMes->_oscAdrSize );
packStartPtr += _newMes->_oscAdrAlignmentSize;
//=========== TypeTag(String) -> BIN Encode ===========
*packStartPtr = ',';
for ( uint8_t i=0 ; i<_newMes->_argsNum ; i++ ) packStartPtr[i+1] = _newMes->getArgTypeTag(i);
packStartPtr += _newMes->_typeTagAlignmentSize;
//=========== Auguments -> BIN Encode ==================
for ( uint8_t i=0 ; i < _newMes->_argsNum ; i++ ) {
switch ( _newMes->getArgTypeTag(i) ) {
case kTagInt32:
case kTagFloat:
case kTagString:
memcpy( packStartPtr, _newMes->_args[i]->_argData, _newMes->getArgAlignmentSize(i) );
break;
default:
break;
}
packStartPtr += _newMes->getArgAlignmentSize(i);
}
return 1;
}