mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-02 01:41:05 +02:00
Merge pull request #1435 from tomaz-beltram/gh-1429
MongoDB BSON type 0x11 support, fixes #1429
This commit is contained in:
commit
ac1f9f243d
@ -291,6 +291,51 @@ inline void BSONWriter::write<NullValue>(NullValue& from)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BSONTimestamp {
|
||||||
|
Poco::Timestamp ts;
|
||||||
|
Poco::Int32 inc;
|
||||||
|
};
|
||||||
|
|
||||||
|
// BSON Timestamp
|
||||||
|
// spec: int64
|
||||||
|
template<>
|
||||||
|
struct ElementTraits<BSONTimestamp>
|
||||||
|
{
|
||||||
|
enum { TypeId = 0x11 };
|
||||||
|
|
||||||
|
static std::string toString(const BSONTimestamp& value, int indent = 0)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
result.append(1, '"');
|
||||||
|
result.append(DateTimeFormatter::format(value.ts, "%Y-%m-%dT%H:%M:%s%z"));
|
||||||
|
result.append(1, ' ');
|
||||||
|
result.append(NumberFormatter::format(value.inc));
|
||||||
|
result.append(1, '"');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BSONReader::read<BSONTimestamp>(BSONTimestamp& to)
|
||||||
|
{
|
||||||
|
Poco::Int64 value;
|
||||||
|
_reader >> value;
|
||||||
|
to.inc = value & 0xffffffff;
|
||||||
|
value >>= 32;
|
||||||
|
to.ts = Timestamp::fromEpochTime(static_cast<std::time_t>(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline void BSONWriter::write<BSONTimestamp>(BSONTimestamp& from)
|
||||||
|
{
|
||||||
|
Poco::Int64 value = from.ts.epochMicroseconds() / 1000;
|
||||||
|
value <<= 32;
|
||||||
|
value += from.inc;
|
||||||
|
_writer << value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// BSON 64-bit integer
|
// BSON 64-bit integer
|
||||||
// spec: int64
|
// spec: int64
|
||||||
|
@ -96,6 +96,9 @@ void Document::read(BinaryReader& reader)
|
|||||||
case ElementTraits<Poco::Timestamp>::TypeId:
|
case ElementTraits<Poco::Timestamp>::TypeId:
|
||||||
element = new ConcreteElement<Poco::Timestamp>(name, Poco::Timestamp());
|
element = new ConcreteElement<Poco::Timestamp>(name, Poco::Timestamp());
|
||||||
break;
|
break;
|
||||||
|
case ElementTraits<BSONTimestamp>::TypeId:
|
||||||
|
element = new ConcreteElement<BSONTimestamp>(name, BSONTimestamp());
|
||||||
|
break;
|
||||||
case ElementTraits<NullValue>::TypeId:
|
case ElementTraits<NullValue>::TypeId:
|
||||||
element = new ConcreteElement<NullValue>(name, NullValue(0));
|
element = new ConcreteElement<NullValue>(name, NullValue(0));
|
||||||
break;
|
break;
|
||||||
@ -111,7 +114,7 @@ void Document::read(BinaryReader& reader)
|
|||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Element " << name << " contains an unsupported type " << std::hex << (int) type;
|
ss << "Element " << name << " contains an unsupported type 0x" << std::hex << (int) type;
|
||||||
throw Poco::NotImplementedException(ss.str());
|
throw Poco::NotImplementedException(ss.str());
|
||||||
}
|
}
|
||||||
//TODO: x0F -> JavaScript code with scope
|
//TODO: x0F -> JavaScript code with scope
|
||||||
|
Loading…
x
Reference in New Issue
Block a user