コード例 #1
0
ファイル: m2mserver.cpp プロジェクト: GoodDada/mbed-client
String M2MServer::resource_value_string(ServerResource resource) const
{
    String value = "";
    M2MResource* res = get_resource(resource);
    if(res && (M2MServer::Binding == resource)) {
        uint8_t* buffer = NULL;
        uint32_t length = 0;
        res->get_value(buffer,length);

        char *char_buffer = (char*)malloc(length+1);
        if(char_buffer) {
            memset(char_buffer,0,length+1);
            memcpy(char_buffer,(char*)buffer,length);

            String s_name(char_buffer);
            value = s_name;
            if(char_buffer) {
                free(char_buffer);
            }
        }
        if(buffer) {
            free(buffer);
        }
    }
    return value;
}
コード例 #2
0
ファイル: m2mserver.cpp プロジェクト: GoodDada/mbed-client
bool M2MServer::set_resource_value(ServerResource resource,
                                   uint32_t value)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MServer::ShortServerID == resource     ||
           M2MServer::Lifetime == resource          ||
           M2MServer::DefaultMinPeriod == resource  ||
           M2MServer::DefaultMaxPeriod == resource  ||
           M2MServer::DisableTimeout == resource    ||
           M2MServer::NotificationStorage == resource) {
            // If it is any of the above resource
            // set the value of the resource.
            char *buffer = (char*)malloc(20);
            if(buffer) {
                int size = snprintf(buffer, 20,"%ld",(long int)value);
                success = res->set_value((const uint8_t*)buffer,
                                         (const uint32_t)size);
                free(buffer);
            }
        }
    }
    return success;
}
コード例 #3
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
bool M2MSecurity::set_resource_value(SecurityResource resource,
                                     uint32_t value)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MSecurity::SecurityMode == resource        ||
           M2MSecurity::SMSSecurityMode == resource     ||
           M2MSecurity::M2MServerSMSNumber == resource  ||
           M2MSecurity::ShortServerID == resource       ||
           M2MSecurity::ClientHoldOffTime == resource) {
            // If it is any of the above resource
            // set the value of the resource.            
            char *buffer = (char*)malloc(BUFFER_SIZE);
            if(buffer) {
                uint32_t size = m2m::itoa_c(value, buffer);
                if (size <= BUFFER_SIZE) {
                    success = res->set_value((const uint8_t*)buffer, size);
                }
                free(buffer);
            }
        }
    }
    return success;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: wotio/FRDMk64f-to-wotio-mds
    M2MObject* create_generic_object() {
        _object = M2MInterfaceFactory::create_object("Test");
        if(_object) {
            M2MObjectInstance* inst = _object->create_object_instance();
            if(inst) {
                    M2MResource* res = inst->create_dynamic_resource("D",
                                                                     "ResourceTest",
                                                                     M2MResourceInstance::INTEGER,
                                                                     true);
                    char buffer[20];
                    int size = sprintf(buffer,"%d",_value);
                    res->set_operation(M2MBase::GET_PUT_ALLOWED);
                    res->set_value((const uint8_t*)buffer,
                                   (const uint32_t)size);
                    _value++;

                    inst->create_static_resource("S",
                                                 "ResourceTest",
                                                 M2MResourceInstance::STRING,
                                                 STATIC_VALUE,
                                                 sizeof(STATIC_VALUE)-1);
            }
        }
        return _object;
    }
コード例 #5
0
ファイル: lwm2mtest.cpp プロジェクト: Blue-Design/mbed-client
bool M2MLWClient::create_dynamic_resource_int(const char *name,
                                          bool observable,
                                          bool multiple_instance,
                                          uint16_t object_instance,
                                          uint8_t resource_operation)
{
    bool success = false;
    String name_string;
    if(name) {
        name_string += name;
    }
    if(_object) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            M2MResource *res = inst->create_dynamic_resource(name,"resource",
                                                             M2MResourceInstance::INTEGER,
                                                             observable, multiple_instance);
            if(res) {
                success = true;
                res->set_operation(int_to_operation(resource_operation));
            }
        }
    }
    return success;
}
コード例 #6
0
bool M2MFirmware::check_value_range(FirmwareResource resource, int64_t value) const
{
    bool success = false;
    switch (resource) {
        case UpdateSupportedObjects:
            if(value == 0 || value == 1) {
                success = true;
            }
            break;
        case State:
            if (value >= 0 && value <= 3) {
                success = true;
                M2MResource* updateRes = get_resource(M2MFirmware::Update);
                if (updateRes){
                    if (value == M2MFirmware::Downloaded) {
                        updateRes->set_operation(M2MBase::POST_ALLOWED);
                    }
                    else {
                        updateRes->set_operation(M2MBase::NOT_ALLOWED);
                    }
                }
            }
            break;
        case UpdateResult:
            if (value >= 0 && value <= 7) {
                success = true;
            }
            break;
    default:
        break;
    }
    return success;
}
コード例 #7
0
 //Callback from mbed client stack if any value has changed
 // during PUT operation. Object and its type is passed in
 // the callback.
 void value_updated(M2MBase *base, M2MBase::BaseType type) {
     output.printf("\nUpdate Object name %s and Type %d\n", base->name().c_str(), type);
     
     // only the LED supports PUT so lets see if its this instance...
     M2MObjectInstance* inst = _sdw_led_object->object_instance();
     if (inst) {
         // should be the /311/0/5850 resource... check for it...
         M2MResource* res = inst->resource("5850");
         if (res != NULL && base == res) {
             // extract the LED value...
             char *new_led_value = (char *)(res->value());
             
             // DEBUG
             printf("\nLight Switch Resource Changed! [%s]\n",new_led_value);
             
             // Update the LED
             if (strcmp(new_led_value,"1") == 0) {
                 __led = 0;
             }
             else {
                 __led = 1;
             }
         }
     }
 }
コード例 #8
0
ファイル: lwm2mtest.cpp プロジェクト: Blue-Design/mbed-client
bool M2MLWClient::set_resource_instance_value(const char *name,
                                              const char *value,
                                              uint16_t object_instance,
                                              uint16_t resource_instance)
{
    bool success = false;
    String name_string;
    String value_string;
    if(name) {
        name_string += name;
    }
    if(value) {
        value_string += value;
    }

    if(_object && name_string.length() > 0) {
        M2MObjectInstance *inst = _object->object_instance(object_instance);
        if(inst) {
            M2MResource *res = inst->resource(name_string);
            if (res) {
                M2MResourceInstance *res_inst = res->resource_instance(resource_instance);
                if(res_inst) {
                    if (res_inst->set_value((const uint8_t*)value_string.c_str(), value_string.size())) {
                        success = true;
                    }
                }
            }
        }
    }
    return success;
}
コード例 #9
0
void Test_M2MResource::test_copy_constructor()
{
    u_int8_t value[] = {"value"};
    resource->set_value(value,(u_int32_t)sizeof(value));

    M2MResourceInstance *res = new M2MResourceInstance("name","type",M2MResourceInstance::STRING,*callback);
    resource->add_resource_instance(res);

    M2MResource* copy = new M2MResource(*resource);
    u_int8_t* out_value = (u_int8_t*)malloc(sizeof(u_int8_t));
    u_int32_t out_size;

    uint8_t* ptr = (uint8_t*)malloc((uint32_t)sizeof(value));
    m2mresourceinstance_stub::value = ptr;
    memset(m2mresourceinstance_stub::value,0,(uint32_t)sizeof(value));
    memcpy(m2mresourceinstance_stub::value,value,sizeof(value));
    m2mresourceinstance_stub::int_value = (uint32_t)sizeof(value);

    copy->get_value(out_value,out_size);

    CHECK(out_size == sizeof(value));

    free(out_value);
    free(ptr);

    delete copy;
}
コード例 #10
0
ファイル: m2mdevice.cpp プロジェクト: Cheong2K/mbed-client
M2MResource* M2MDevice::create_resource(DeviceResource resource)
{
    M2MResource* res = NULL;
    if(!is_resource_present(resource)) {
        String device_Id;
        if(FactoryReset == resource) {
            device_Id = DEVICE_FACTORY_RESET;
        } else if(ResetErrorCode == resource) {
            device_Id = DEVICE_RESET_ERROR_CODE;
        }
        if(_device_instance && !device_Id.empty()) {
            res = _device_instance->create_dynamic_resource(device_Id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::OPAQUE,
                                                            true);
            M2MResource *resource = _device_instance->resource(device_Id);
            if(resource) {
                resource->set_register_uri(false);
            }
            if(res) {
                res->set_operation(M2MBase::POST_ALLOWED);
                res->set_register_uri(false);
            }
        }
    }
    return res;
}
コード例 #11
0
 M2MObject* create_led_object() {
     _sdw_led_object = M2MInterfaceFactory::create_object("311");
     
     if (_sdw_led_object) {
         M2MObjectInstance* inst = _sdw_led_object->create_object_instance();
         if (inst) {
             M2MResource* res = inst->create_dynamic_resource("5850",
                                                              "LED",
                                                              M2MResourceInstance::STRING,
                                                              false);
             if (res) {
                 char buffer[10] = "";
                 memset(buffer,0,10);
                 strcpy(buffer,"0");
                 if (__led == 1) strcpy(buffer,"1");
                 
                 // set the value of the LED 
                 res->set_operation(M2MBase::GET_PUT_ALLOWED);   // we allow GET and PUT of the LED
                 res->set_value((const uint8_t*)buffer,
                                (const uint32_t)strlen(buffer));
             }
         }
     }
     return _sdw_led_object;
 }
コード例 #12
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
String M2MSecurity::resource_value_string(SecurityResource resource) const
{
    String value = "";
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MSecurity::M2MServerUri == resource) {
            uint8_t* buffer = NULL;
            uint32_t length = 0;
            res->get_value(buffer,length);

            char *char_buffer = (char*)malloc(length+1);
            if(char_buffer) {
                memset(char_buffer,0,length+1);
                if(buffer) {
                    memcpy(char_buffer,(char*)buffer,length);                    
                }
                String s_name(char_buffer);
                value = s_name;
                free(char_buffer);
            }
            if(buffer) {
                free(buffer);
            }
        }
    }
    return value;
}
コード例 #13
0
ファイル: m2mdevice.cpp プロジェクト: GoodDada/mbed-client
M2MResource* M2MDevice::create_resource(DeviceResource resource, const String &value)
{
    M2MResource* res = NULL;
    String device_id = "";
    M2MBase::Operation operation = M2MBase::GET_ALLOWED;
    if(!is_resource_present(resource)) {
        switch(resource) {
            case Manufacturer:
               device_id = DEVICE_MANUFACTURER;
               break;
            case DeviceType:
                device_id = DEVICE_DEVICE_TYPE;
                break;
            case ModelNumber:
                device_id = DEVICE_MODEL_NUMBER;
                break;
            case SerialNumber:
                device_id = DEVICE_SERIAL_NUMBER;
                break;
            case HardwareVersion:
                device_id = DEVICE_HARDWARE_VERSION;
                break;
            case FirmwareVersion:
                device_id = DEVICE_FIRMWARE_VERSION;
                break;
            case SoftwareVersion:
                device_id = DEVICE_SOFTWARE_VERSION;
                break;
            case UTCOffset:
                device_id = DEVICE_UTC_OFFSET;
                operation = M2MBase::GET_PUT_ALLOWED;
                break;
            case Timezone:
                device_id = DEVICE_TIMEZONE;
                operation = M2MBase::GET_PUT_ALLOWED;
                break;
            default:
                break;
        }
    }
    if(!device_id.empty()) {
        if(_device_instance) {
            res = _device_instance->create_dynamic_resource(device_id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::STRING,
                                                            false);

            if(res ) {
                res->set_operation(operation);
                res->set_value((const uint8_t*)value.c_str(),
                               (uint32_t)value.length());
            }
        }
    }
    return res;
}
コード例 #14
0
ファイル: m2mserver.cpp プロジェクト: GoodDada/mbed-client
bool M2MServer::set_resource_value(ServerResource resource,
                                   const String &value)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res && (M2MServer::Binding == resource)) {
        success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length());
    }
    return success;
}
コード例 #15
0
ファイル: m2mdevice.cpp プロジェクト: Cheong2K/mbed-client
M2MResource* M2MDevice::create_resource(DeviceResource resource, int64_t value)
{
    M2MResource* res = NULL;
    String device_id = "";
    M2MBase::Operation operation = M2MBase::GET_ALLOWED;
    if(!is_resource_present(resource)) {
        switch(resource) {        
        case BatteryLevel:
            if(check_value_range(resource, value)) {
                device_id = DEVICE_BATTERY_LEVEL;
            }
            break;
        case BatteryStatus:
            if(check_value_range(resource, value)) {
                device_id = DEVICE_BATTERY_STATUS;
            }
            break;
        case MemoryFree:
            device_id = DEVICE_MEMORY_FREE;
            break;
        case MemoryTotal:
            device_id = DEVICE_MEMORY_TOTAL;
            break;
        case CurrentTime:
            device_id = DEVICE_CURRENT_TIME;
            operation = M2MBase::GET_PUT_ALLOWED;
            break;
        default:
            break;
        }
    }
    if(!device_id.empty()) {
        if(_device_instance) {
            res = _device_instance->create_dynamic_resource(device_id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::INTEGER,
                                                            true);

            if(res) {
                char *buffer = (char*)malloc(BUFFER_SIZE);
                if(buffer) {
                    uint32_t size = m2m::itoa_c(value, buffer);
                    if (size <= BUFFER_SIZE) {
                        res->set_operation(operation);
                        res->set_value((const uint8_t*)buffer, size);
                    }
                    free(buffer);
                }
                res->set_register_uri(false);
            }
        }
    }
    return res;
}
コード例 #16
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
bool M2MSecurity::set_resource_value(SecurityResource resource,
                                     const String &value)
{
    bool success = false;
    if(M2MSecurity::M2MServerUri == resource) {
        M2MResource* res = get_resource(resource);
        if(res) {
            success = res->set_value((const uint8_t*)value.c_str(),(uint32_t)value.length());
        }
    }
    return success;
}
コード例 #17
0
uint32_t M2MFirmware::resource_value_buffer(FirmwareResource resource,
                               uint8_t *&data) const
{
    uint32_t size = 0;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MFirmware::Package == resource) {
            res->get_value(data,size);
        }
    }
    return size;
}
コード例 #18
0
ファイル: m2mdevice.cpp プロジェクト: GoodDada/mbed-client
M2MResource* M2MDevice::create_resource(DeviceResource resource, int64_t value)
{
    M2MResource* res = NULL;
    String device_id = "";
    M2MBase::Operation operation = M2MBase::GET_ALLOWED;
    if(!is_resource_present(resource)) {
        switch(resource) {
        case BatteryLevel:
            if(0 <= value && value <= 100) {
                device_id = DEVICE_BATTERY_LEVEL;
            }
            break;
        case BatteryStatus:
            if(0 <= value && value <= 6) {
                device_id = DEVICE_BATTERY_STATUS;
            }
            break;
        case MemoryFree:
            device_id = DEVICE_MEMORY_FREE;
            break;
        case MemoryTotal:
            device_id = DEVICE_MEMORY_TOTAL;
            break;
        case CurrentTime:
            device_id = DEVICE_CURRENT_TIME;
            operation = M2MBase::GET_PUT_ALLOWED;
            break;
        default:
            break;
        }
    }
    if(!device_id.empty()) {
        if(_device_instance) {
            res = _device_instance->create_dynamic_resource(device_id,
                                                            OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::INTEGER,
                                                            false);

            if(res) {
                char *buffer = (char*)memory_alloc(20);
                if(buffer) {
                    int size = snprintf(buffer, 20,"%ld",value);

                    res->set_operation(operation);
                    res->set_value((const uint8_t*)buffer,
                                   (const uint32_t)size);
                    memory_free(buffer);
                }
            }
        }
    }
    return res;
}
コード例 #19
0
    /*
     * When you press the button, we read the current value of the click counter
     * from mbed Device Connector, then up the value with one.
     */
    void handle_state_change(DoorIndicator::WarnStatus warnStatus) {
        M2MObjectInstance* inst = btn_object->object_instance();
        M2MResource* res = inst->resource("5501");

        printf("handle_state_change, new value of state is %d\r\n", (int) warnStatus);

        // serialize the value of counter as a string, and tell connector
        stringstream ss;
        ss << (int) warnStatus;
        std::string stringified = ss.str();
        res->set_value((uint8_t*)stringified.c_str(), stringified.length());
    }
コード例 #20
0
bool M2MFirmware::set_resource_value(FirmwareResource resource,
                                     const uint8_t *value,
                                     const uint32_t length)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MFirmware::Package == resource) {
            success = res->set_value(value,length);
        }
    }
    return success;
}
コード例 #21
0
ファイル: lwm2mtest.cpp プロジェクト: Blue-Design/mbed-client
void M2MLWClient::set_fw_execute_function()
{
    if(_firmware) {
        M2MObjectInstance *inst = _firmware->object_instance(0);
        if(inst) {
            M2MResource *res = inst->resource("2");
            if (res) {                
                res->set_execute_function(execute_callback(
                                              this,
                                              &M2MLWClient::fw_execute_function));
            }
        }
    }
}
コード例 #22
0
String M2MFirmware::resource_value_string(FirmwareResource resource) const
{
    String value = "";
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MFirmware::PackageUri == resource          ||
           M2MFirmware::PackageName == resource           ||
           M2MFirmware::PackageVersion == resource) {

            value = res->get_value_string();
        }
    }
    return value;
}
コード例 #23
0
int64_t M2MFirmware::resource_value_int(FirmwareResource resource) const
{
    int64_t value = -1;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MFirmware::State == resource          ||
           M2MFirmware::UpdateSupportedObjects == resource         ||
           M2MFirmware::UpdateResult == resource) {

            value = res->get_value_int();
        }
    }
    return value;
}
コード例 #24
0
    void update_resource() {
        if(_object) {
            M2MObjectInstance* inst = _object->object_instance();
            if(inst) {
                    M2MResource* res = inst->resource("D");

                    char buffer[20];
                    int size = sprintf(buffer,"%d",_value);
                    res->set_value((const uint8_t*)buffer,
                                   (const uint32_t)size);
                    _value++;
                }
        }
    }
コード例 #25
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
uint32_t M2MSecurity::resource_value_buffer(SecurityResource resource,
                               uint8_t *&data) const
{
    uint32_t size = 0;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MSecurity::PublicKey == resource        ||
           M2MSecurity::ServerPublicKey == resource  ||
           M2MSecurity::Secretkey == resource) {
            res->get_value(data,size);
        }
    }
    return size;
}
コード例 #26
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
bool M2MSecurity::set_resource_value(SecurityResource resource,
                                     const uint8_t *value,
                                     const uint16_t length)
{
    bool success = false;
    M2MResource* res = get_resource(resource);
    if(res) {
        if(M2MSecurity::PublicKey == resource           ||
           M2MSecurity::ServerPublicKey == resource     ||
           M2MSecurity::Secretkey == resource) {
            success = res->set_value(value,length);
        }
    }
    return success;
}
コード例 #27
0
ファイル: m2mdevice.cpp プロジェクト: Cheong2K/mbed-client
M2MResourceInstance* M2MDevice::create_resource_instance(DeviceResource resource, int64_t value,
                                                 uint16_t instance_id)
{
    M2MResourceInstance* res = NULL;
    String device_id = "";    
    // For these resources multiple instance can exist
    if(AvailablePowerSources == resource) {
        if(check_value_range(resource, value)) {
            device_id = DEVICE_AVAILABLE_POWER_SOURCES;
        }
    } else if(PowerSourceVoltage == resource) {
        device_id = DEVICE_POWER_SOURCE_VOLTAGE;
    } else if(PowerSourceCurrent == resource) {
        device_id = DEVICE_POWER_SOURCE_CURRENT;
    } else if(ErrorCode == resource) {
        if(check_value_range(resource, value)) {
            device_id = DEVICE_ERROR_CODE;
        }
    }

    if(!device_id.empty()) {
        if(_device_instance) {
            res = _device_instance->create_dynamic_resource_instance(device_id,OMA_RESOURCE_TYPE,
                                                                     M2MResourceInstance::INTEGER,
                                                                     true, instance_id);

            M2MResource *resource = _device_instance->resource(device_id);
            if(resource) {
                resource->set_register_uri(false);
            }
            if(res) {
                char *buffer = (char*)malloc(BUFFER_SIZE);
                if(buffer) {
                    uint32_t size = m2m::itoa_c(value, buffer);
                    if (size <= BUFFER_SIZE) {
                        res->set_value((const uint8_t*)buffer, size);
                        // Only read operation is allowed for above resources
                        res->set_operation(M2MBase::GET_ALLOWED);
                    }
                    free(buffer);
                }
                res->set_register_uri(false);
            }
        }
    }
    return res;
}
コード例 #28
0
ファイル: m2mdevice.cpp プロジェクト: Cheong2K/mbed-client
M2MResourceInstance* M2MDevice::get_resource_instance(DeviceResource dev_res,
                                                      uint16_t instance_id) const
{
    M2MResource* res = NULL;
    M2MResourceInstance* inst = NULL;
    if(_device_instance) {
        res = _device_instance->resource(resource_name(dev_res));
        if(res) {
            if(res->supports_multiple_instances()) {
               inst = res->resource_instance(instance_id);
            } else {
                inst = res;
            }
        }
    }
    return inst;
}
コード例 #29
0
ファイル: m2mserver.cpp プロジェクト: GoodDada/mbed-client
M2MResource* M2MServer::create_resource(ServerResource resource)
{
    M2MResource* res = NULL;
    if(!is_resource_present(resource)) {
        if(M2MServer::Disable == resource) {
                if(_server_instance) {
                    res = _server_instance->create_dynamic_resource(SERVER_DISABLE,
                                                                    OMA_RESOURCE_TYPE,
                                                                    M2MResourceInstance::OPAQUE,
                                                                    false);
                if(res) {
                    res->set_operation(M2MBase::POST_ALLOWED);
                }
            }
        }
    }
    return res;
}
コード例 #30
0
ファイル: m2msecurity.cpp プロジェクト: brianjang/mbed-client
M2MResource* M2MSecurity::create_resource(SecurityResource resource, uint32_t value)
{
    M2MResource* res = NULL;
    String security_id = "";
    if(!is_resource_present(resource)) {
        switch(resource) {
            case SMSSecurityMode:
               security_id = SECURITY_SMS_SECURITY_MODE;
               break;
            case M2MServerSMSNumber:
                security_id = SECURITY_M2M_SERVER_SMS_NUMBER;
                break;
            case ShortServerID:
                security_id = SECURITY_SHORT_SERVER_ID;
                break;
            case ClientHoldOffTime:
                security_id = SECURITY_CLIENT_HOLD_OFF_TIME;
                break;
            default:
                break;
        }
    }
    if(!security_id.empty()) {
        if(_server_instance) {

            res = _server_instance->create_dynamic_resource(security_id,OMA_RESOURCE_TYPE,
                                                            M2MResourceInstance::INTEGER,
                                                            false);

            if(res) {
                res->set_operation(M2MBase::NOT_ALLOWED);
                char *buffer = (char*)malloc(BUFFER_SIZE);
                if(buffer) {
                    uint32_t size = m2m::itoa_c(value, buffer);
                    if (size <= BUFFER_SIZE) {
                        res->set_value((const uint8_t*)buffer, size);
                    }
                    free(buffer);
                }
            }
        }
    }
    return res;
}