Permalink
Browse files

Beginings of token stream parsing. No useful functionality yet.

  • Loading branch information...
1 parent b30c938 commit 560369761309af54796d8a310c092944d8695604 @pekim pekim committed Oct 27, 2011
View
@@ -5,3 +5,5 @@ todo
*sublime*
npm-debug.log
coffee/*
+
+test/unit/perf-buffer.coffee
View
@@ -1,3 +1,4 @@
+require('buffertools')
Debug = require('./debug')
EventEmitter = require('events').EventEmitter
TYPE = require('./packet').TYPE
@@ -0,0 +1,3 @@
+
+module.exports = ->
+ console.log('env-change-parser!')
View
@@ -1,3 +1,4 @@
+require('buffertools')
EventEmitter = require('events').EventEmitter
isPacketComplete = require('./packet').isPacketComplete
packetLength = require('./packet').packetLength
@@ -0,0 +1,36 @@
+require('buffertools')
+EventEmitter = require('events').EventEmitter
+TYPE = require('./token').TYPE
+
+tokenParsers = {}
+tokenParsers[TYPE.ENVCHANGE] = require('./env-change-parser')
+
+class Parser extends EventEmitter
+ constructor: () ->
+ @buffer = new Buffer(0)
+ @position = 0
+
+ addBuffer: (buffer) ->
+ @buffer = new Buffer(@buffer.concat(buffer))
+
+ while @nextToken()
+ 'NOOP'
+
+ nextToken: ->
+ type = @buffer.readUInt8(@position)
+ @position++
+
+ if tokenParsers[type]
+ token = tokenParsers[type](@buffer, @position)
+ if token
+ @position += token.length
+ else
+ false
+
+ else
+ console.log("Unknown token type #{type}")
+ false
+
+ false
+
+exports.Parser = Parser
View
@@ -0,0 +1,29 @@
+
+
+# s2.2.5.7
+TYPE =
+ ALTMETADATA: 0x88,
+ ALTROW: 0xD3,
+ COLMETADATA: 0x81,
+ COLINFO: 0xA5,
+ DONE: 0xFD,
+ DONEPROC: 0xFE,
+ DONEINPROC: 0xFF,
+ ENVCHANGE: 0xE3,
+ ERROR: 0xAA,
+ INFO: 0xAB,
+ LOGINACK: 0xAD,
+ NBCROW: 0xD2,
+ OFFSET: 0x78,
+ ORDER: 0xA9,
+ RETURNSTATUS: 0x79,
+ RETURNVALUE: 0xAC,
+ ROW: 0xD1,
+ SSPI: 0xED,
+ TABNAME: 0xA4
+
+#typeByValue = {}
+#for name, value of TYPE
+# typeByValue[value] = name
+
+exports.TYPE = TYPE
@@ -0,0 +1,23 @@
+Parser = require('../../lib/token-stream-parser').Parser
+TYPE = require('../../lib/token').TYPE
+
+module.exports.nop = (test) ->
+ oldDb = 'old'
+ newDb = 'new'
+
+ buffer = new Buffer(1 + 2 + 1 + 1 + (oldDb.length * 2) + 1 + (newDb.length * 2))
+ pos = 0;
+
+ buffer.writeUInt8(TYPE.ENVCHANGE, pos); pos++
+ buffer.writeUInt16LE(buffer.length - (1 + 2), pos); pos += 2
+ buffer.writeUInt8(0x01, pos); pos++ #Database
+ buffer.writeUInt8(oldDb.length, pos); pos++
+ buffer.write(oldDb, pos, 'ucs-2'); pos += (oldDb.length * 2)
+ buffer.writeUInt8(newDb.length, pos); pos++
+ buffer.write(newDb, pos, 'ucs-2'); pos += (newDb.length * 2)
+ console.log(buffer)
+
+ parser = new Parser()
+ parser.addBuffer(buffer)
+
+ test.done()

0 comments on commit 5603697

Please sign in to comment.