-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from buyology/add-int-and-double-assignment
Add support for int and double assignment
- Loading branch information
Showing
6 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package assign | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/senseyeio/roger/constants" | ||
) | ||
|
||
func assignDouble(symbol string, value float64) ([]byte, error) { | ||
rl := 8 | ||
|
||
symn := []byte(symbol) | ||
sl := len(symn) + 1 | ||
if (sl & 3) > 0 { | ||
sl = (sl & 0xfffffc) + 4 | ||
} | ||
|
||
var rq []byte | ||
|
||
shl := GetHeaderLength(constants.DtString, sl) | ||
sextHeader := GetHeaderLength(constants.DataType(constants.XtDouble), rl) | ||
rhl := GetHeaderLength(constants.DtSexp, rl+sextHeader) | ||
|
||
rq = make([]byte, sl+rl+shl+rhl+sextHeader) | ||
|
||
ic := 0 | ||
for ; ic < len(symn); ic++ { | ||
rq[ic+shl] = symn[ic] | ||
} | ||
for ic < sl { | ||
rq[ic+shl] = 0 | ||
ic++ | ||
} | ||
|
||
setHdrOffset(constants.DtString, sl, rq, 0) | ||
setHdrOffset(constants.DtSexp, rl+sextHeader, rq, sl+shl) | ||
|
||
off := sl + shl + rhl | ||
setHdrOffset(constants.DataType(constants.XtDouble), rl, rq, off) | ||
off += sextHeader | ||
|
||
setLong(int64(math.Float64bits(value)), rq, off) | ||
|
||
return rq, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package assign | ||
|
||
import ( | ||
"github.com/senseyeio/roger/constants" | ||
) | ||
|
||
func assignInt(symbol string, value int32) ([]byte, error) { | ||
rl := 4 | ||
|
||
symn := []byte(symbol) | ||
sl := len(symn) + 1 | ||
if (sl & 3) > 0 { | ||
sl = (sl & 0xfffffc) + 4 | ||
} | ||
|
||
var rq []byte | ||
|
||
shl := GetHeaderLength(constants.DtString, sl) | ||
sextHeader := GetHeaderLength(constants.DataType(constants.XtInt), rl) | ||
rhl := GetHeaderLength(constants.DtSexp, rl+sextHeader) | ||
|
||
rq = make([]byte, sl+rl+shl+rhl+sextHeader) | ||
|
||
ic := 0 | ||
for ; ic < len(symn); ic++ { | ||
rq[ic+shl] = symn[ic] | ||
} | ||
for ic < sl { | ||
rq[ic+shl] = 0 | ||
ic++ | ||
} | ||
|
||
setHdrOffset(constants.DtString, sl, rq, 0) | ||
setHdrOffset(constants.DtSexp, rl+sextHeader, rq, sl+shl) | ||
|
||
off := sl + shl + rhl | ||
setHdrOffset(constants.DataType(constants.XtInt), rl, rq, off) | ||
off += sextHeader | ||
|
||
SetInt(int(value), rq, off) | ||
|
||
return rq, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters