Пример #1
0
void BinDataInfo::finalize(js::FreeOp* fop, JSObject* obj) {
    auto str = getEncoded(obj);

    if (str) {
        getScope(fop)->trackedDelete(str);
    }
}
Пример #2
0
unsigned AudioStream::getEncoded(AudioCodec *codec, Encoded addr, unsigned frames)
{
    Info ci;
    unsigned count = 0;
    unsigned bufsize = 0;
    unsigned used = 0;
    bool eof = false;

    if(!codec)
        return getEncoded(addr, frames);

    ci = codec->getInfo();

    if(ci.encoding == info.encoding && ci.framecount == info.framecount)
        return getEncoded(addr, frames);

    if(!is_streamable())
        return 0;

    while(bufsize < ci.framesize)
        bufsize += info.framesize;

    if(encSize != bufsize) {
        if(encBuffer)
            delete[] encBuffer;

        encBuffer = new Sample[bufsize];
        encSize = bufsize;
    }

    while(count < frames && !eof) {
        while(used < ci.framesize) {
            if(getMono(encBuffer + used, 1) < 1) {
                eof = true;
                break;
            }
            used += info.framesize;
        }
        codec->encode(encBuffer, addr, ci.framesize);
        if(ci.framesize < used)
            memcpy(encBuffer, encBuffer + ci.framesize, used - ci.framesize);
        used -= ci.framesize;
    }
    return count;
}
Пример #3
0
void RobotTelemetry::scheduledSend() {

        while (isEnabled) {
        	semTake(mRobotTelemetry,WAIT_FOREVER);
        	//update the data
        	updateTelemetryData();
        	//send the data
        	bhs_PCDataServer::getInstance().xmitRawData(getId(),getLength(),getEncoded());
        	semGive(mRobotTelemetry);
        	Wait(sendRate);
        }
}
Пример #4
0
void BinDataInfo::Functions::toJSON::call(JSContext* cx, JS::CallArgs args) {
    ObjectWrapper o(cx, args.thisv());

    auto data_str = getEncoded(args.thisv());

    std::stringstream ss;
    ss << std::hex;
    ss.width(2);
    ss.fill('0');
    ss << o.getNumber(InternedString::type);

    ValueReader(cx, args.rval())
        .fromBSON(BSON("$binary" << *data_str << "$type" << ss.str()), nullptr, false);
}
Пример #5
0
void BinDataInfo::Functions::hex::call(JSContext* cx, JS::CallArgs args) {
    auto str = getEncoded(args.thisv());

    std::string data = mongo::base64::decode(*str);
    std::stringstream ss;
    ss.setf(std::ios_base::hex, std::ios_base::basefield);
    ss.fill('0');
    ss.setf(std::ios_base::right, std::ios_base::adjustfield);
    for (auto it = data.begin(); it != data.end(); ++it) {
        unsigned v = (unsigned char)*it;
        ss << std::setw(2) << v;
    }

    ValueReader(cx, args.rval()).fromStringData(ss.str());
}
Пример #6
0
void BinDataInfo::Functions::toString::call(JSContext* cx, JS::CallArgs args) {
    ObjectWrapper o(cx, args.thisv());

    auto str = getEncoded(args.thisv());

    str::stream ss;
    auto binType = o.getNumber(InternedString::type);

    if (binType == newUUID) {
        auto decoded = mongo::base64::decode(*str);

        // If this is in fact a UUID, use a more friendly string representation.
        if (decoded.length() == mongo::UUID::kNumBytes) {
            mongo::UUID uuid = mongo::UUID::fromCDR({decoded.data(), decoded.length()});
            ss << "UUID(\"" << uuid.toString() << "\")";
            ValueReader(cx, args.rval()).fromStringData(ss.operator std::string());
            return;
        }
    }

    ss << "BinData(" << binType << ",\"" << *str << "\")";
    ValueReader(cx, args.rval()).fromStringData(ss.operator std::string());
}
Пример #7
0
void BinDataInfo::Functions::base64::call(JSContext* cx, JS::CallArgs args) {
    auto str = getEncoded(args.thisv());

    ValueReader(cx, args.rval()).fromStringData(*str);
}
Пример #8
0
/*
  write the platform-dependent iteration through a directory.
  Basic Algorithm:
  For each element in the directory
  if the element is a directory (and recurse is non-zero)
  recursively call addDirectory
  if the element is a file
  stat the file and allocate a new NESHARE_FILE_OBJ
  encode the filename and fill in the OBJ
*/
int neFileManager::addDirectory(char *directory, int recurse)
{
    int ret = 1;
    int count = 0;
   
    /* get the base path directory (and format properly) */
    std::string basePath = formatBasePath(directory);

    struct dirent *dentry = NULL;
    DIR *dir = opendir(basePath.c_str());
    if (dir)
    {
        while((dentry = readdir(dir)))
        {
            if (dentry->d_name[0] == '.')
            {
                continue;
            }

            /*
              stat the file to get the file size and
              distinguish b/w a dir and regular file
            */
            struct stat statbuf;
            memset(&statbuf,0,sizeof(statbuf));
            std::string direntry = basePath +
                std::string(dentry->d_name);

            if (stat((char *)direntry.c_str(),&statbuf))
            {
                continue;
            }

            /* handle directory entry */
            if (S_ISDIR(statbuf.st_mode))
            {
                if (recurse)
                {
                    /* adjust the basePath and recurse */
                    std::string newBasePath = basePath +
                        std::string(dentry->d_name);
                    ret = addDirectory((char *)newBasePath.c_str(),
                                       recurse);
                }

                /* count directories as files as well */
                count++;
            }
            else /* handle file entry */
            {
                /* format the filename */
                std::string filename = getEncoded(
                    (char *)basePath.c_str(),dentry->d_name);
         
                /* create a new file entry to map */
                NESHARE_FILE_OBJ *newFileObj = new NESHARE_FILE_OBJ();
                if ((basePath.length() + strlen(dentry->d_name)) <
                    NEFILE_MAX_NAME_LEN)
                {
                    newFileObj->fileSize = (unsigned long)statbuf.st_size;
                    strcpy(newFileObj->realFilename,basePath.c_str());
                    strcat(newFileObj->realFilename,dentry->d_name);
                    strcpy(newFileObj->encodedFilename,filename.c_str());

                    /* finally, insert the file into the map */
                    m_encodedFilenames[filename] = newFileObj;
                    count++;
                }
                else
                {
                    iprintf("Filename too long.  Skipping %s\n",
                            dentry->d_name);
                    delete newFileObj;
                    continue;
                }
            }
        }
        closedir(dir);
        ret = (((count > 0) || (ret == 0)) ? 0 : 1);
    }
    return ret;
}
ByteArray LinkLocalServiceInfo::toTXTRecord() const {
    ByteArray result(getEncoded("txtvers=1"));
    if (!firstName.empty()) {
        result += getEncoded("1st=" + firstName);
    }
    if (!lastName.empty()) {
        result += getEncoded("last=" + lastName);
    }
    if (!email.empty()) {
        result += getEncoded("email=" + email);
    }
    if (jid.isValid()) {
        result += getEncoded("jid=" + jid.toString());
    }
    if (!message.empty()) {
        result += getEncoded("msg=" + message);
    }
    if (!nick.empty()) {
        result += getEncoded("nick=" + nick);
    }
    if (port) {
        result += getEncoded("port.p2pj=" + std::string(boost::lexical_cast<std::string>(*port)));
    }

    switch (status) {
    case Available:
        result += getEncoded("status=avail");
        break;
    case Away:
        result += getEncoded("status=away");
        break;
    case DND:
        result += getEncoded("status=dnd");
        break;
    }

    return result;
}