本文整理汇总了C++中Brn::Bytes方法的典型用法代码示例。如果您正苦于以下问题:C++ Brn::Bytes方法的具体用法?C++ Brn::Bytes怎么用?C++ Brn::Bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Brn
的用法示例。
在下文中一共展示了Brn::Bytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Process
void SsdpHeaderUsn::Process(const Brx& aValue)
{
SetReceived();
Parser parser(aValue);
Brn prefix = parser.Next(':');
if (prefix != kUuid) {
THROW(HttpError);
}
Brn uuid = parser.Next(':');
if (uuid.Bytes() > kMaxUuidBytes) {
THROW(HttpError);
}
iUuid.Replace(uuid);
if (parser.Next(kUuidSeparator).Bytes() != 0) { // double colon separator
THROW(HttpError);
}
Brn value = parser.Remaining();
if (value.Bytes() == 0) {
iTarget = eSsdpUuid;
return;
}
if (value == kUpnpRoot) {
iTarget = eSsdpRoot;
return;
}
Brn type = parser.Next(':');
if (type == kMsearchUrn) {
Brn domain = parser.Next(':');
Brn kind = parser.Next(':');
Brn type = parser.Next(':');
if (domain.Bytes() > kMaxDomainBytes) {
THROW(HttpError);
}
Ssdp::UpnpDomainToCanonical(domain, iDomain);
if (type.Bytes() > kMaxTypeBytes) {
THROW(HttpError);
}
iType.Replace(type);
try {
iVersion = Ascii::Uint(parser.Remaining());
}
catch (AsciiError&) {
THROW(HttpError);
}
if (kind == kMsearchDevice) {
iTarget = eSsdpDeviceType;
return;
}
if (kind == kMsearchService) {
iTarget = eSsdpServiceType;
return;
}
}
THROW(HttpError);
}
示例2: Process
void HeaderCallback::Process(const Brx& aValue)
{
SetReceived();
Parser parser(aValue);
parser.Next('<');
Brn uri = parser.Next('>');
TUint bytes = uri.Bytes();
if (bytes < Http::kUriPrefix.Bytes()) {
THROW(HttpError);
}
if (uri.Split(0, Http::kUriPrefix.Bytes()) != Http::kUriPrefix) {
THROW(HttpError);
}
parser.Set(uri.Split(Http::kUriPrefix.Bytes()));
Brn address = parser.Next(':');
Brn port = parser.Next('/');
try {
iEndpoint = OpenHome::Endpoint(Ascii::Uint(port), address);
}
catch (AsciiError) {
THROW(HttpError);
}
Brn remaining = parser.Remaining();
iUri.Grow(remaining.Bytes() + 1);
iUri.Replace(Brn("/"));
iUri.Append(remaining);
}
示例3: ReadProtocol
Brn ReaderUntil::ReadProtocol(TUint aBytes)
{
ASSERT(aBytes <= iMaxBytes);
TByte* start = Ptr() + iOffset;
TByte* p = start;
if (aBytes <= iBytes - iOffset) {
iOffset += aBytes;
if (iOffset == iBytes) {
iBytes = 0;
iOffset = 0;
}
return Brn(start, aBytes);
}
if (iBytes > 0) {
iBytes -= iOffset;
start = Ptr();
(void)memmove(start, start + iOffset, iBytes);
p = start + iBytes;
iOffset = 0;
aBytes -= iBytes;
}
TUint remaining = aBytes;
while (remaining > 0) {
Brn buf = iReader.Read(remaining);
(void)memcpy(p, buf.Ptr(), buf.Bytes());
p += buf.Bytes();
}
iBytes = 0;
iOffset = 0;
return Brn(start, (TUint)(p - start));
}
示例4: WriteResource
void DviProtocolUpnp::WriteResource(const Brx& aUriTail, TIpAddress aAdapter, std::vector<char*>& aLanguageList, IResourceWriter& aResourceWriter)
{
if (aUriTail == kDeviceXmlName) {
Brh xml;
Brn xmlBuf;
AutoMutex _(iLock);
const TInt index = FindListenerForInterface(aAdapter);
if (index == -1) {
return;
}
if (iDevice.IsRoot()) {
const Brx& cachedXml = iAdapters[index]->DeviceXml();
if (cachedXml.Bytes() > 0) {
xmlBuf.Set(cachedXml);
}
}
if (xmlBuf.Bytes() == 0) {
GetDeviceXml(xml, aAdapter);
if (iDevice.IsRoot()) {
iAdapters[index]->SetDeviceXml(xml);
xmlBuf.Set(iAdapters[index]->DeviceXml());
}
else {
xmlBuf.Set(xml);
}
}
aResourceWriter.WriteResourceBegin(xmlBuf.Bytes(), kOhNetMimeTypeXml);
aResourceWriter.WriteResource(xmlBuf.Ptr(), xmlBuf.Bytes());
aResourceWriter.WriteResourceEnd();
}
else {
Parser parser(aUriTail);
Brn buf = parser.Next('/');
Brn rem = parser.Remaining();
if (buf == DviDevice::kResourceDir) {
IResourceManager* resMgr = iDevice.ResourceManager();
if (resMgr != NULL) {
resMgr->WriteResource(rem, aAdapter, aLanguageList, aResourceWriter);
}
}
else if (rem == kServiceXmlName) {
iLock.Wait();
DviService* service = 0;
const TUint count = iDevice.ServiceCount();
for (TUint i=0; i<count; i++) {
DviService& s = iDevice.Service(i);
if (s.ServiceType().PathUpnp() == buf) {
service = &s;
break;
}
}
iLock.Signal();
if (service == 0) {
THROW(ReaderError);
}
DviProtocolUpnpServiceXmlWriter::Write(*service, *this, aResourceWriter);
}
}
}
示例5: Read
void XmlFetch::Read()
{
iDechunker.ReadFlush();
ReaderHttpResponse readerResponse(iCpStack.Env(), iReaderUntil);
HttpHeaderContentLength headerContentLength;
HttpHeaderTransferEncoding headerTransferEncoding;
readerResponse.AddHeader(headerContentLength);
readerResponse.AddHeader(headerTransferEncoding);
readerResponse.Read(kResponseTimeoutMs);
const HttpStatus& status = readerResponse.Status();
if (status != HttpStatus::kOk) {
LOG2(kXmlFetch, kError, "XmlFetch::Read, http error %u ", status.Code());
LOG2(kXmlFetch, kError, status.Reason());
LOG2(kXmlFetch, kError, "\n");
SetError(Error::eHttp, status.Code(), status.Reason());
THROW(HttpError);
}
if (iCheckContactable) {
iContactable = true;
return;
}
WriterBwh writer(1024);
static const TUint kMaxReadBytes = 4 * 1024;
if (headerTransferEncoding.IsChunked()) {
iDechunker.SetChunked(true);
for (;;) {
Brn buf = iDechunker.Read(kMaxReadBytes);
writer.Write(buf);
if (buf.Bytes() == 0) { // end of stream
break;
}
}
}
else {
TUint remaining = headerContentLength.ContentLength();
if (remaining == 0) { // no content length - read until connection closed by server
try {
for (;;) {
writer.Write(iReaderUntil.Read(kMaxReadBytes));
}
}
catch (ReaderError&) {
}
}
else {
do {
Brn buf = iReaderUntil.Read(kMaxReadBytes);
remaining -= buf.Bytes();
writer.Write(buf);
} while (remaining > 0);
}
}
writer.TransferTo(iXml);
}
示例6: InvocationReadBinary
void DviSessionLpec::InvocationReadBinary(const TChar* /*aName*/, Brh& aData)
{
(void)iParser.Next(Lpec::kArgumentDelimiter);
Brn val = iParser.NextNoTrim(Lpec::kArgumentDelimiter);
if (val.Bytes() != 0) {
Bwh writable(val.Bytes()+1);
writable.Append(val);
Converter::FromBase64(writable);
writable.TransferTo(aData);
}
}
示例7: InvocationReadString
void DviSessionLpec::InvocationReadString(const TChar* /*aName*/, Brhz& aString)
{
(void)iParser.Next(Lpec::kArgumentDelimiter);
Brn val = iParser.NextNoTrim(Lpec::kArgumentDelimiter);
Bwh writable(val.Bytes()+1);
if (val.Bytes()) {
writable.Append(val);
Converter::FromXmlEscaped(writable);
}
writable.PtrZ();
writable.TransferTo(aString);
}
示例8: UdnMatches
TBool CpiDeviceUpnp::UdnMatches(const Brx& aFound, const Brx& aTarget)
{
const Brn udnPrefix("uuid:");
Brn udn(aFound);
if (udn.Bytes() <= udnPrefix.Bytes()) {
THROW(XmlError);
}
Brn prefix = udn.Split(0, udnPrefix.Bytes());
if (prefix != udnPrefix) {
THROW(XmlError);
}
udn.Set(udn.Split(udnPrefix.Bytes(), udn.Bytes() - udnPrefix.Bytes()));
return (udn == aTarget);
}
示例9: InvocationReadBinary
void DviSessionUpnp::InvocationReadBinary(const TChar* aName, Brh& aData)
{
try {
Brn value = XmlParserBasic::Find(aName, iSoapRequest);
if (value.Bytes()) {
Bwh writable(value.Bytes()+1);
writable.Append(value);
Converter::FromBase64(writable);
writable.TransferTo(aData);
}
}
catch (XmlError&) {
InvocationReportError(501, Brn("Invalid XML"));
}
}
示例10: InvocationReadBool
TBool DviSessionLpec::InvocationReadBool(const TChar* /*aName*/)
{
(void)iParser.Next(Lpec::kArgumentDelimiter);
Brn val = iParser.Next(Lpec::kArgumentDelimiter);
if (Ascii::CaseInsensitiveEquals(val, Lpec::kBoolFalse) ||
(val.Bytes() == 1 && val[0] == '0')) {
return false;
}
if (Ascii::CaseInsensitiveEquals(val, Lpec::kBoolTrue) ||
(val.Bytes() == 1 && val[0] == '1')) {
return true;
}
ReportError(LpecError::kInvalidArgBool);
return false; // never reached
}
示例11: Read
void ReaderHttpChunked::Read()
{
for (;;) {
Brn chunkSizeBuf = iReader.ReadUntil(Ascii::kLf);
Parser parser(chunkSizeBuf);
Brn trimmed = parser.Next(Ascii::kCr);
if (trimmed.Bytes() == 0) {
continue;
}
TUint chunkSize;
try {
chunkSize = Ascii::UintHex(trimmed);
}
catch (AsciiError&) {
THROW(ReaderError);
}
if (chunkSize == 0) {
break;
}
iEntity.Grow(iEntity.Bytes() + chunkSize);
while (chunkSize > 0) {
TUint bytes = (chunkSize<4096? chunkSize : 4096);
iEntity.Append(iReader.Read(bytes));
chunkSize -= bytes;
}
}
}
示例12: Process
void HttpHeaderContentType::Process(const Brx& aValue)
{
Parser parser(aValue);
try {
Brn type = parser.Next(';');
Parser parser2(type); // get first word of the type
iType.Replace(parser2.Next());
SetReceived();
}
catch (BufferOverflow&) {
return;
}
Brn key;
Brn value;
for (;;) {
key.Set(parser.Next('='));
if (key.Bytes() == 0) {
return;
}
value.Set(parser.Next());
Process(key, value);
}
}
示例13: SetAttribute
void DviDevice::SetAttribute(const TChar* aKey, const TChar* aValue)
{
Brn key(aKey);
Parser parser(key);
Brn name = parser.Next('.');
aKey += name.Bytes() + 1;
// assume keys starting 'Test' are a special case which can be updated at any time
if (strlen(aKey) < 4 || strncmp(aKey, "Test", 4) != 0) {
ASSERT(iEnabled == eDisabled);
}
if (name == Brn("Core")) {
static const char* longPollEnable = "LongPollEnable";
if (iProviderSubscriptionLongPoll == NULL &&
strncmp(aKey, longPollEnable, sizeof(longPollEnable)-1) == 0) {
iProviderSubscriptionLongPoll = new DviProviderSubscriptionLongPoll(*this);
ConfigChanged();
}
}
else {
for (TUint i=0; i<(TUint)iProtocols.size(); i++) {
IDvProtocol* protocol = iProtocols[i];
if (protocol->ProtocolName() == name) {
protocol->SetAttribute(aKey, aValue);
ConfigChanged();
break;
}
}
}
}
示例14: GetAttribute
void DviProtocolUpnp::GetAttribute(const TChar* aKey, const TChar** aValue) const
{
*aValue = iAttributeMap.Get(aKey);
if (*aValue == NULL) {
Brn key(aKey);
static const Brn kServicePrefix("Service.");
if (key.BeginsWith(kServicePrefix)) {
Brn pathUpnp = key.Split(kServicePrefix.Bytes());
const TUint count = iDevice.ServiceCount();
for (TUint i=0; i<count; i++) {
DviService& service = iDevice.Service(i);
Bws<128> name(service.ServiceType().Domain());
const TUint bytes = name.Bytes();
for (TUint j=0; j<bytes; j++) {
if (name[j] == '.') {
name[j] = '-';
}
}
name.Append('.');
name.Append(service.ServiceType().Name());
if (name == pathUpnp) {
*aValue = (const TChar*)(service.ServiceType().VersionBuf().Ptr());
return;
}
}
}
}
}
示例15: Unsubscribe
void DviSessionLpec::Unsubscribe()
{
AutoMutex a(iSubscriptionLock);
Brn cmd = Ascii::Trim(iParser.Remaining());
if (cmd.Bytes() == 0) {
for (TUint i=0; i<iSubscriptions.size(); i++) {
DoUnsubscribe(0);
}
return;
}
try {
const TUint lpecSid = Ascii::Uint(cmd);
for (TUint i=0; i<iSubscriptions.size(); i++) {
if (iSubscriptions[i].LpecSid() == lpecSid) {
DoUnsubscribe(i);
return;
}
}
ReportError(LpecError::kSubscriptionNotFound);
}
catch (AsciiError&) {
// not a sid, fall through to below to check for device/service
}
AutoMutex b(iDeviceLock);
ParseDeviceAndService();
for (TUint i=0; i<iSubscriptions.size(); i++) {
if (iSubscriptions[i].Matches(*iTargetDevice, *iTargetService)) {
DoUnsubscribe(i);
return;
}
}
ReportError(LpecError::kServiceNotSubscribed);
}