How to use the serialize function from bson
Find comprehensive JavaScript bson.serialize code examples handpicked from public code repositorys.
GitHub: dtube/avalon
121 122 123 124 125 126 127 128 129 130
logr.info('Index reconstructed up to block #'+blocks.height+' in '+(new Date().getTime()-startTime)+'ms') }, appendBlock: (newBlock) => { assert(blocks.isOpen,blocks.notOpenError) assert(newBlock._id === blocks.height+1,'could not append non-next block') let serializedBlock = BSON.serialize(newBlock) let newBlockSize = BigInt(serializedBlock.length) fs.writeSync(blocks.fd,serializedBlock) blocks.appendIndex(blocks.bsonSize) blocks.bsonSize += newBlockSize
64
93
0
41 42 43 44 45 46 47 48 49 50
const id = uuid.v4(); this.amqp.channel.publish( process.env.RABBITMQ_EXCHANGE, process.env.RABBITMQ_ROUTING_KEY, bson.serialize(req.body), { headers: { 'x-resource-id': id } } ); reply.status(202)
5
50
2
43 44 45 46 47 48 49 50 51 52
// Serialize document const doc = { long: Long.fromNumber(100) } // Serialize a document const data = BSON.serialize(doc) // De serialize it again const doc_2 = BSON.deserialize(data) } </script>
1
1
3
+ 7 other calls in file
177 178 179 180 181 182 183 184 185 186
socket.addMembership('239.10.102.50', localAddress); var hb = new HeartbeatObject(); hb.ServerName = os.hostname(); var message = bson.serialize(hb); setInterval(function() { //console.log("Sending heartbeat (" + message + ")"); //var message = new Buffer('This is a test');
0
5
2
5 6 7 8 9 10 11 12 13 14 15
function BSONDecode(buffer) { return bson.deserialize(buffer.slice(4)); } function BSONEncode(json) { const data = bson.serialize(json); var buf = Buffer.alloc(4 + data.byteLength); buf.writeInt32LE(4 + data.byteLength); data.copy(buf, 4); return buf;
0
4
0
142 143 144 145 146 147 148 149 150 151 152
// * Serealize data to BSON // * @param {Object} object object to serialize // * @returns {Buffer} serialized object // */ // const BJSONSerialize = (object) => { // return serialize(object); // } // /** // * Deserealize data from BSON
0
0
0
bson.ObjectId is the most popular function in bson (1017 examples)