Transfer Buffer through "remote"

This commit is contained in:
Cheng Zhao 2015-06-09 17:46:33 +08:00
parent 200a19dad9
commit 4b12a95d37
2 changed files with 7 additions and 0 deletions

View file

@ -7,6 +7,7 @@ v8Util = process.atomBinding 'v8_util'
valueToMeta = (sender, value) ->
meta = type: typeof value
meta.type = 'buffer' if Buffer.isBuffer value
meta.type = 'value' if value is null
meta.type = 'array' if Array.isArray value
@ -26,6 +27,8 @@ valueToMeta = (sender, value) ->
meta.members = []
meta.members.push {name: prop, type: typeof field} for prop, field of value
else if meta.type is 'buffer'
meta.value = Array::slice.call value, 0
else
meta.type = 'value'
meta.value = value
@ -43,6 +46,7 @@ unwrapArgs = (sender, args) ->
when 'value' then meta.value
when 'remote-object' then objectsRegistry.get meta.id
when 'array' then unwrapArgs sender, meta.value
when 'buffer' then new Buffer(meta.value)
when 'object'
ret = v8Util.createObjectWithName meta.name
for member in meta.members

View file

@ -10,6 +10,8 @@ wrapArgs = (args) ->
valueToMeta = (value) ->
if Array.isArray value
type: 'array', value: wrapArgs(value)
else if Buffer.isBuffer value
type: 'buffer', value: Array::slice.call(value, 0)
else if value? and typeof value is 'object' and v8Util.getHiddenValue value, 'atomId'
type: 'remote-object', id: v8Util.getHiddenValue value, 'atomId'
else if value? and typeof value is 'object'
@ -30,6 +32,7 @@ metaToValue = (meta) ->
switch meta.type
when 'value' then meta.value
when 'array' then (metaToValue(el) for el in meta.members)
when 'buffer' then new Buffer(meta.value)
when 'error'
throw new Error("#{meta.message}\n#{meta.stack}")
else