forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyped-value.js
56 lines (49 loc) · 1.46 KB
/
typed-value.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
const ValuedType = require('../constant/valued-type').ValuedType
const annotationMessages = require('./grpc/Annotation_pb')
const {convertStringStringValue} = require('./grpc-data-convertor')
class TypedValue {
constructor(value, valuedType) {
switch (typeof value) {
case 'number':
this.intValue = value
break;
case 'boolean':
this.boolValue = value
break;
case 'string':
this.stringValue = value
break;
case 'object':
if (valuedType === ValuedType.stringStringValue) {
this.stringStringValue = value
}
break;
case 'undefined':
this.stringValue = value
break;
}
}
static of (value) {
return new TypedValue(value)
}
annotationValue() {
const pAnnotationValue = new annotationMessages.PAnnotationValue()
if (this.hasOwnProperty('intValue')) {
pAnnotationValue.setIntvalue(this.intValue)
} else if (this.hasOwnProperty('boolValue')) {
pAnnotationValue.setBoolvalue(this.boolValue)
} else if (this.hasOwnProperty('stringValue')) {
pAnnotationValue.setStringvalue(this.stringValue)
} else if (this.hasOwnProperty('stringStringValue')) {
pAnnotationValue.setStringstringvalue(convertStringStringValue(this.stringStringValue))
}
return pAnnotationValue
}
}
module.exports = TypedValue