Commit 972946b6 authored by EXT Arnaud Clère's avatar EXT Arnaud Clère
Browse files

Added bool support

parent c5a0260f
......@@ -59,6 +59,8 @@ enum MajorTypes {
//! CBOR simple and floating point types
//! Encoded in the low 5 bits of the descriptor byte when the Major Type is 7.
enum SimpleTypes {
FalseValue = 20,
TrueValue = 21,
NullValue = 22,
SinglePrecisionFloat = 26,
DoublePrecisionFloat = 27,
......@@ -80,7 +82,9 @@ enum : unsigned char {
BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift),
IndefiniteLengthArrayByte = IndefiniteLength | (ArrayType << MajorTypeShift),
NullByte = NullValue | (SimpleTypesType << MajorTypeShift)
NullByte = NullValue | (SimpleTypesType << MajorTypeShift),
TrueByte = TrueValue | (SimpleTypesType << MajorTypeShift),
FalseByte = FalseValue | (SimpleTypesType << MajorTypeShift)
};
enum tag{
......@@ -126,6 +130,7 @@ protected:
bool _bind(const char* s,int min=1) { return (putInteger(cbor::TextStringType, strlen(s)) && io->write(s)) || min<=0; }
// Natively supported overloads
bool _bind( bool b,int min=1) { return io->putChar(b ? cbor::TrueByte : cbor::FalseByte) || min<=0; }
bool _bind( float n,int min=1) { union { float value; quint32 bits; } number = { n };
char bytes[sizeof(number.bits)]; qToBigEndian(number.bits, bytes);
return (io->putChar((cbor::SimpleTypesType << cbor::MajorTypeShift) | cbor::SinglePrecisionFloat) && io->write(bytes, sizeof(bytes))) || min<=0; }
......
......@@ -169,6 +169,7 @@ int main()
QBuffer b;
b.open(QIODevice::ReadWrite);
// TODO Benchmark against QDataStream
GROUP("<atoms")
{
START {
......@@ -176,6 +177,7 @@ int main()
QDebug(&s)
<< '[' << 1.333333333333f
<< ',' << text
<< ',' << false
<< ']'
;
}
......@@ -186,6 +188,7 @@ int main()
.sequence()
.bind(1.333333333333f)
.bind(text)
.bind(false)
;
}
STOP("Text",QString::fromUtf8(b.buffer()));
......@@ -195,6 +198,7 @@ int main()
.sequence()
.bind(1.333333333333f)
.bind(text)
.bind(false)
;
}
STOP("Json",QString::fromUtf8(b.buffer()));
......@@ -204,6 +208,7 @@ int main()
.sequence()
.bind(1.333333333333f)
.bind(text)
.bind(false)
;
}
STOP("Cbor",QString::fromUtf8(b.buffer().toHex()));
......@@ -212,6 +217,7 @@ int main()
writables.clear();
writables.append(1.333333333333f);
writables.append(text);
writables.append(false);
}
STOP("Writables","");
START {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment