]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/nodejs/lib/thrift/binary.js
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 var POW_8
= Math
.pow(2, 8);
21 var POW_16
= Math
.pow(2, 16);
22 var POW_24
= Math
.pow(2, 24);
23 var POW_32
= Math
.pow(2, 32);
24 var POW_40
= Math
.pow(2, 40);
25 var POW_48
= Math
.pow(2, 48);
26 var POW_52
= Math
.pow(2, 52);
27 var POW_1022
= Math
.pow(2, 1022);
29 exports
.readByte = function(b
){
30 return b
> 127 ? b
-256 : b
;
33 exports
.readI16 = function(buff
, off
) {
35 var v
= buff
[off
+ 1];
37 if (buff
[off
] & 128) {
43 exports
.readI32 = function(buff
, off
) {
45 var v
= buff
[off
+ 3];
46 v
+= buff
[off
+ 2] << 8;
47 v
+= buff
[off
+ 1] << 16;
48 v
+= buff
[off
] * POW_24
;
49 if (buff
[off
] & 0x80) {
55 exports
.writeI16 = function(buff
, v
) {
62 exports
.writeI32 = function(buff
, v
) {
73 exports
.readDouble = function(buff
, off
) {
75 var signed
= buff
[off
] & 0x80;
76 var e
= (buff
[off
+1] & 0xF0) >> 4;
77 e
+= (buff
[off
] & 0x7F) << 4;
80 m
+= buff
[off
+6] << 8;
81 m
+= buff
[off
+5] << 16;
82 m
+= buff
[off
+4] * POW_24
;
83 m
+= buff
[off
+3] * POW_32
;
84 m
+= buff
[off
+2] * POW_40
;
85 m
+= (buff
[off
+1] & 0x0F) * POW_48
;
92 return m
? NaN
: (signed
? -Infinity
: Infinity
);
102 return m
* Math
.pow(2, e
- 52);
106 * Based on code from the jspack module:
107 * http://code.google.com/p/jspack/
109 exports
.writeDouble = function(buff
, v
) {
112 buff
[0] = (v
< 0 ? 0x80 : 0x00);
116 // NaN, use QNaN IEEE format
117 m
= 2251799813685248;
119 } else if (v
=== Infinity
) {
123 e
= Math
.floor(Math
.log(v
) / Math
.LN2
);
130 if (e
+ 1023 >= 2047)
136 else if (e
+ 1023 >= 1)
138 // Normalized - term order matters, as Math.pow(2, 52-e) and v*Math.pow(2, 52) can overflow
139 m
= (v
*c
-1) * POW_52
;
144 // Denormalized - also catches the '0' case, somewhat by chance
145 m
= (v
* POW_1022
) * POW_52
;
150 buff
[1] = (e
<< 4) & 0xf0;
151 buff
[0] |= (e
>> 4) & 0x7f;
154 m
= Math
.floor(m
/ POW_8
);
156 m
= Math
.floor(m
/ POW_8
);
158 m
= Math
.floor(m
/ POW_8
);