Skip to content

Commit

Permalink
Efficiency improvements when querying blob and address.
Browse files Browse the repository at this point in the history
Allows obtaining a pointer to:
 * blob data
 * message's address as a string
  • Loading branch information
szekelyisz committed Feb 14, 2019
1 parent 9569624 commit ee9521a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ Copy ‘size’ bytes from the blob, starting from ‘offset’, into the given
Returns the number of bytes copied from the blob.


### `const uint8_t* getBlob(int position)`

Get a pointer to blob data.


### `int getBlobLength(int position)`

Returns the length of the blob in bytes.
Expand Down Expand Up @@ -198,6 +203,10 @@ Set the address of the OSCMessage.
Copy the address of the OSCMessage into the `str` buffer. Copy after the given address offset (defaults to 0).
### `const char* getAddress()`
Get a pointer to the address as a C string.
## Send Receive
Expand Down
4 changes: 3 additions & 1 deletion OSCData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ int OSCData::getBlob(uint8_t * blobBuffer, int length, int offset, int size){
}
}


const uint8_t* OSCData::getBlob() {
return type == 'b' ? data.b + 4 : NULL;
}

int OSCData::getBlobLength(){
if (type == 'b'){
Expand Down
1 change: 1 addition & 0 deletions OSCData.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class OSCData
int getBlob(uint8_t *);
int getBlob(uint8_t *, int);
int getBlob(uint8_t *, int, int, int);
const uint8_t* getBlob();
int getBlobLength();
bool getBoolean();
osctime_t getTime();
Expand Down
13 changes: 13 additions & 0 deletions OSCMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ int OSCMessage::getBlob(int position, uint8_t * buffer, int bufferSize, int offs
}
}

const uint8_t* OSCMessage::getBlob(int position) {
OSCData* datum = getOSCData(position);
if(!hasError()) {
return datum->getBlob();
} else {
return NULL;
}
}

uint32_t OSCMessage::getBlobLength(int position)
{
OSCData * datum = getOSCData(position);
Expand Down Expand Up @@ -408,6 +417,10 @@ int OSCMessage::getAddress(char * buffer, int offset, int len){
return strlen(buffer);
}

const char* OSCMessage::getAddress(){
return address;
}

OSCMessage& OSCMessage::setAddress(const char * _address){
//free the previous address
free(address); // are we sure address was allocated?
Expand Down
4 changes: 4 additions & 0 deletions OSCMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class OSCMessage
int getBlob(int, uint8_t *, int);
//offset and size can be defined in order to only query a part of the blob's content
int getBlob(int, uint8_t *, int, int, int);
//get pointer to blob
const uint8_t* getBlob(int);


// returns the length of blob
Expand All @@ -271,6 +273,8 @@ class OSCMessage
//put the address in the buffer
int getAddress(char * buffer, int offset = 0);
int getAddress(char * buffer, int offset, int len);
//get pointer to address
const char* getAddress();

// TODO: int getAddressLength(int offset = 0);

Expand Down

0 comments on commit ee9521a

Please sign in to comment.