From fbae728a2ee771dbcd3694b808fa2f46d71a705a Mon Sep 17 00:00:00 2001 From: Sascha Matzke Date: Fri, 6 Mar 2009 14:37:11 +0100 Subject: [PATCH] added support (write/read) for timestamps --- bson/reader/reader.factor | 6 +++++- bson/writer/writer.factor | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bson/reader/reader.factor b/bson/reader/reader.factor index 44eadef973..ca2d5a5bb3 100644 --- a/bson/reader/reader.factor +++ b/bson/reader/reader.factor @@ -1,6 +1,6 @@ USING: accessors assocs bson.constants byte-arrays byte-vectors fry io io.binary io.encodings.string io.encodings.utf8 kernel math namespaces -sequences serialize arrays ; +sequences serialize arrays calendar ; IN: bson.reader @@ -168,6 +168,10 @@ M: bson-boolean element-data-read ( type -- boolean ) drop read-byte t = ; +M: bson-date element-data-read ( type -- timestamp ) + drop + read-longlong millis>timestamp ; + M: bson-binary element-data-read ( type -- binary ) drop read-int32 read-byte element-binary-read ; diff --git a/bson/writer/writer.factor b/bson/writer/writer.factor index db452f4029..6db25b7d1c 100644 --- a/bson/writer/writer.factor +++ b/bson/writer/writer.factor @@ -3,7 +3,7 @@ USING: accessors assocs bson.constants byte-arrays fry io io.binary io.encodings.binary io.encodings.string io.encodings.utf8 io.streams.byte-array kernel math math.parser quotations sequences -serialize strings words tools.hexdump ; +serialize strings words calendar ; IN: bson.writer @@ -24,6 +24,7 @@ M: sequence bson-type? ( seq -- type ) drop T_Array ; M: string bson-type? ( string -- type ) drop T_String ; M: integer bson-type? ( integer -- type ) drop T_Integer ; M: assoc bson-type? ( assoc -- type ) drop T_Object ; +M: timestamp bson-type? ( timestamp -- type ) drop T_Date ; M: oid bson-type? ( word -- type ) drop T_OID ; M: objid bson-type? ( objid -- type ) drop T_Binary ; @@ -59,6 +60,9 @@ M: integer bson-write ( num -- ) M: real bson-write ( num -- ) >float write-double ; +M: timestamp bson-write ( timestamp -- ) + timestamp>millis write-longlong ; + M: byte-array bson-write ( binary -- ) [ length write-int32 ] keep T_Binary_Bytes write-byte