/
MessageTable.sol
140 lines (110 loc) · 5.32 KB
/
MessageTable.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/* Autogenerated file. Do not edit manually. */
// Import schema type
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
// Import store internals
import { IStore } from "@latticexyz/store/src/IStore.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
import { Memory } from "@latticexyz/store/src/Memory.sol";
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.sol";
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol";
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol";
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
ResourceId constant _tableId = ResourceId.wrap(
bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14(""), bytes16("MessageTable")))
);
ResourceId constant MessageTableTableId = _tableId;
FieldLayout constant _fieldLayout = FieldLayout.wrap(
0x0000000100000000000000000000000000000000000000000000000000000000
);
library MessageTable {
/** Get the table values' field layout */
function getFieldLayout() internal pure returns (FieldLayout) {
return _fieldLayout;
}
/** Get the table's key schema */
function getKeySchema() internal pure returns (Schema) {
SchemaType[] memory _keySchema = new SchemaType[](0);
return SchemaLib.encode(_keySchema);
}
/** Get the table's value schema */
function getValueSchema() internal pure returns (Schema) {
SchemaType[] memory _valueSchema = new SchemaType[](1);
_valueSchema[0] = SchemaType.STRING;
return SchemaLib.encode(_valueSchema);
}
/** Get the table's key names */
function getKeyNames() internal pure returns (string[] memory keyNames) {
keyNames = new string[](0);
}
/** Get the table's field names */
function getFieldNames() internal pure returns (string[] memory fieldNames) {
fieldNames = new string[](1);
fieldNames[0] = "value";
}
/** Register the table with its config */
function register() internal {
StoreSwitch.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
}
/** Register the table with its config */
function _register() internal {
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
}
/** Register the table with its config (using the specified store) */
function register(IStore _store) internal {
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
}
/** Emit the ephemeral event using individual values */
function emitEphemeral(string memory value) internal {
bytes memory _staticData;
PackedCounter _encodedLengths = encodeLengths(value);
bytes memory _dynamicData = encodeDynamic(value);
bytes32[] memory _keyTuple = new bytes32[](0);
StoreSwitch.emitEphemeralRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
}
/** Emit the ephemeral event using individual values */
function _emitEphemeral(string memory value) internal {
bytes memory _staticData;
PackedCounter _encodedLengths = encodeLengths(value);
bytes memory _dynamicData = encodeDynamic(value);
bytes32[] memory _keyTuple = new bytes32[](0);
StoreCore.emitEphemeralRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
}
/** Emit the ephemeral event using individual values (using the specified store) */
function emitEphemeral(IStore _store, string memory value) internal {
bytes memory _staticData;
PackedCounter _encodedLengths = encodeLengths(value);
bytes memory _dynamicData = encodeDynamic(value);
bytes32[] memory _keyTuple = new bytes32[](0);
_store.emitEphemeralRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
}
/** Tightly pack dynamic data using this table's schema */
function encodeLengths(string memory value) internal pure returns (PackedCounter _encodedLengths) {
// Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits
unchecked {
_encodedLengths = PackedCounterLib.pack(bytes(value).length);
}
}
/** Tightly pack dynamic data using this table's schema */
function encodeDynamic(string memory value) internal pure returns (bytes memory) {
return abi.encodePacked(bytes((value)));
}
/** Tightly pack full data using this table's field layout */
function encode(string memory value) internal pure returns (bytes memory, PackedCounter, bytes memory) {
bytes memory _staticData;
PackedCounter _encodedLengths = encodeLengths(value);
bytes memory _dynamicData = encodeDynamic(value);
return (_staticData, _encodedLengths, _dynamicData);
}
/** Encode keys as a bytes32 array using this table's field layout */
function encodeKeyTuple() internal pure returns (bytes32[] memory) {
bytes32[] memory _keyTuple = new bytes32[](0);
return _keyTuple;
}
}