forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibFileServer.sol
86 lines (69 loc) · 2.72 KB
/
LibFileServer.sol
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
*@file LibFileServer.sol
*@author kelvin
*@time 2016-11-29
*@desc the defination of LibFileServer
*/
pragma solidity ^0.4.2;
import "LibInt.sol";
import "LibString.sol";
library LibFileServer {
using LibInt for *;
using LibString for *;
using LibFileServer for *;
/** @brief User state: invalid, valid */
enum ServerState { INVALID, VALID}
/** @brief File Structure */
struct FileServerInfo {
string id;
string host;
uint256 port;
uint256 updateTime;
string organization;
string position;
string group;
string info;
uint256 enable;
ServerState state;
}
function toJson(FileServerInfo storage _self) internal returns(string _strjson){
_strjson = "{";
_strjson = _strjson.concat(_self.id.toKeyValue("id"), ",");
_strjson = _strjson.concat(_self.host.toKeyValue("host"), ",");
_strjson = _strjson.concat(uint(_self.port).toKeyValue("port"), ",");
_strjson = _strjson.concat(uint(_self.updateTime).toKeyValue("updateTime"), ",");
_strjson = _strjson.concat(_self.position.toKeyValue("position"), ",");
_strjson = _strjson.concat(_self.group.toKeyValue("group"), ",");
_strjson = _strjson.concat(_self.organization.toKeyValue("organization"), ",");
_strjson = _strjson.concat(uint(_self.enable).toKeyValue("enable"), ",");
_strjson = _strjson.concat(_self.info.toKeyValue("info"), "}");
}
function jsonParse(FileServerInfo storage _self, string _json) internal returns(bool) {
_self.reset();
_self.id = _json.getStringValueByKey("id");
_self.host = _json.getStringValueByKey("host");
_self.port = uint256(_json.getIntValueByKey("port"));
//_self.updateTime = uint256(_json.getIntValueByKey("updateTime"));
_self.position = _json.getStringValueByKey("position");
_self.group = _json.getStringValueByKey("group");
_self.organization = _json.getStringValueByKey("organization");
_self.info = _json.getStringValueByKey("info");
_self.enable = (uint256)(_json.getIntValueByKey("enable"));
if (bytes(_self.id).length == 0) {
return false;
}
return true;
}
function reset(FileServerInfo storage _self) internal {
_self.id = "";
_self.host = "";
_self.port = 0;
_self.updateTime = 0;
_self.position = "";
_self.organization = "";
_self.info = "";
_self.group = "";
_self.enable = 0;
_self.state = ServerState.INVALID;
}
}