wa-lang.org/wazero@v1.0.2/imports/proxywasm/internal/abi_hostcalls_mock.go (about) 1 // Copyright 2020-2021 Tetrate 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build !tinygo 16 17 // TODO: Auto generate this file from abi_hostcalls.go. 18 19 package internal 20 21 import ( 22 "sync" 23 ) 24 25 var ( 26 currentHost ProxyWasmHost 27 mutex = &sync.Mutex{} 28 ) 29 30 func RegisterMockWasmHost(host ProxyWasmHost) (release func()) { 31 mutex.Lock() 32 currentHost = host 33 return func() { 34 mutex.Unlock() 35 } 36 } 37 38 type ProxyWasmHost interface { 39 ProxyLog(logLevel LogLevel, messageData *byte, messageSize int) Status 40 ProxySetProperty(pathData *byte, pathSize int, valueData *byte, valueSize int) Status 41 ProxyGetProperty(pathData *byte, pathSize int, returnValueData **byte, returnValueSize *int) Status 42 ProxySendLocalResponse(statusCode uint32, statusCodeDetailData *byte, statusCodeDetailsSize int, bodyData *byte, bodySize int, headersData *byte, headersSize int, grpcStatus int32) Status 43 ProxyGetSharedData(keyData *byte, keySize int, returnValueData **byte, returnValueSize *int, returnCas *uint32) Status 44 ProxySetSharedData(keyData *byte, keySize int, valueData *byte, valueSize int, cas uint32) Status 45 ProxyRegisterSharedQueue(nameData *byte, nameSize int, returnID *uint32) Status 46 ProxyResolveSharedQueue(vmIDData *byte, vmIDSize int, nameData *byte, nameSize int, returnID *uint32) Status 47 ProxyDequeueSharedQueue(queueID uint32, returnValueData **byte, returnValueSize *int) Status 48 ProxyEnqueueSharedQueue(queueID uint32, valueData *byte, valueSize int) Status 49 ProxyGetHeaderMapValue(mapType MapType, keyData *byte, keySize int, returnValueData **byte, returnValueSize *int) Status 50 ProxyAddHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status 51 ProxyReplaceHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status 52 ProxyContinueStream(streamType StreamType) Status 53 ProxyCloseStream(streamType StreamType) Status 54 ProxyRemoveHeaderMapValue(mapType MapType, keyData *byte, keySize int) Status 55 ProxyGetHeaderMapPairs(mapType MapType, returnValueData **byte, returnValueSize *int) Status 56 ProxySetHeaderMapPairs(mapType MapType, mapData *byte, mapSize int) Status 57 ProxyGetBufferBytes(bufferType BufferType, start int, maxSize int, returnBufferData **byte, returnBufferSize *int) Status 58 ProxySetBufferBytes(bufferType BufferType, start int, maxSize int, bufferData *byte, bufferSize int) Status 59 ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte, bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) Status 60 ProxyCallForeignFunction(funcNamePtr *byte, funcNameSize int, paramPtr *byte, paramSize int, returnData **byte, returnSize *int) Status 61 ProxySetTickPeriodMilliseconds(period uint32) Status 62 ProxySetEffectiveContext(contextID uint32) Status 63 ProxyDone() Status 64 ProxyDefineMetric(metricType MetricType, metricNameData *byte, metricNameSize int, returnMetricIDPtr *uint32) Status 65 ProxyIncrementMetric(metricID uint32, offset int64) Status 66 ProxyRecordMetric(metricID uint32, value uint64) Status 67 ProxyGetMetric(metricID uint32, returnMetricValue *uint64) Status 68 } 69 70 type DefaultProxyWAMSHost struct{} 71 72 var _ ProxyWasmHost = DefaultProxyWAMSHost{} 73 74 func (d DefaultProxyWAMSHost) ProxyLog(logLevel LogLevel, messageData *byte, messageSize int) Status { 75 return 0 76 } 77 func (d DefaultProxyWAMSHost) ProxySetProperty(pathData *byte, pathSize int, valueData *byte, valueSize int) Status { 78 return 0 79 } 80 func (d DefaultProxyWAMSHost) ProxyGetProperty(pathData *byte, pathSize int, returnValueData **byte, returnValueSize *int) Status { 81 return 0 82 } 83 func (d DefaultProxyWAMSHost) ProxySendLocalResponse(statusCode uint32, statusCodeDetailData *byte, statusCodeDetailsSize int, bodyData *byte, bodySize int, headersData *byte, headersSize int, grpcStatus int32) Status { 84 return 0 85 } 86 func (d DefaultProxyWAMSHost) ProxyGetSharedData(keyData *byte, keySize int, returnValueData **byte, returnValueSize *int, returnCas *uint32) Status { 87 return 0 88 } 89 func (d DefaultProxyWAMSHost) ProxySetSharedData(keyData *byte, keySize int, valueData *byte, valueSize int, cas uint32) Status { 90 return 0 91 } 92 func (d DefaultProxyWAMSHost) ProxyRegisterSharedQueue(nameData *byte, nameSize int, returnID *uint32) Status { 93 return 0 94 } 95 func (d DefaultProxyWAMSHost) ProxyResolveSharedQueue(vmIDData *byte, vmIDSize int, nameData *byte, nameSize int, returnID *uint32) Status { 96 return 0 97 } 98 func (d DefaultProxyWAMSHost) ProxyDequeueSharedQueue(queueID uint32, returnValueData **byte, returnValueSize *int) Status { 99 return 0 100 } 101 func (d DefaultProxyWAMSHost) ProxyEnqueueSharedQueue(queueID uint32, valueData *byte, valueSize int) Status { 102 return 0 103 } 104 func (d DefaultProxyWAMSHost) ProxyGetHeaderMapValue(mapType MapType, keyData *byte, keySize int, returnValueData **byte, returnValueSize *int) Status { 105 return 0 106 } 107 func (d DefaultProxyWAMSHost) ProxyAddHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status { 108 return 0 109 } 110 func (d DefaultProxyWAMSHost) ProxyReplaceHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status { 111 return 0 112 } 113 func (d DefaultProxyWAMSHost) ProxyContinueStream(streamType StreamType) Status { return 0 } 114 func (d DefaultProxyWAMSHost) ProxyCloseStream(streamType StreamType) Status { return 0 } 115 func (d DefaultProxyWAMSHost) ProxyRemoveHeaderMapValue(mapType MapType, keyData *byte, keySize int) Status { 116 return 0 117 } 118 func (d DefaultProxyWAMSHost) ProxyGetHeaderMapPairs(mapType MapType, returnValueData **byte, returnValueSize *int) Status { 119 return 0 120 } 121 func (d DefaultProxyWAMSHost) ProxySetHeaderMapPairs(mapType MapType, mapData *byte, mapSize int) Status { 122 return 0 123 } 124 func (d DefaultProxyWAMSHost) ProxyGetBufferBytes(bufferType BufferType, start int, maxSize int, returnBufferData **byte, returnBufferSize *int) Status { 125 return 0 126 } 127 func (d DefaultProxyWAMSHost) ProxySetBufferBytes(bufferType BufferType, start int, maxSize int, bufferData *byte, bufferSize int) Status { 128 return 0 129 } 130 func (d DefaultProxyWAMSHost) ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte, bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) Status { 131 return 0 132 } 133 func (d DefaultProxyWAMSHost) ProxyCallForeignFunction(funcNamePtr *byte, funcNameSize int, paramPtr *byte, paramSize int, returnData **byte, returnSize *int) Status { 134 return 0 135 } 136 func (d DefaultProxyWAMSHost) ProxySetTickPeriodMilliseconds(period uint32) Status { return 0 } 137 func (d DefaultProxyWAMSHost) ProxySetEffectiveContext(contextID uint32) Status { return 0 } 138 func (d DefaultProxyWAMSHost) ProxyDone() Status { return 0 } 139 func (d DefaultProxyWAMSHost) ProxyDefineMetric(metricType MetricType, metricNameData *byte, metricNameSize int, returnMetricIDPtr *uint32) Status { 140 return 0 141 } 142 func (d DefaultProxyWAMSHost) ProxyIncrementMetric(metricID uint32, offset int64) Status { 143 return 0 144 } 145 func (d DefaultProxyWAMSHost) ProxyRecordMetric(metricID uint32, value uint64) Status { return 0 } 146 func (d DefaultProxyWAMSHost) ProxyGetMetric(metricID uint32, returnMetricValue *uint64) Status { 147 return 0 148 } 149 150 func ProxyLog(logLevel LogLevel, messageData *byte, messageSize int) Status { 151 return currentHost.ProxyLog(logLevel, messageData, messageSize) 152 } 153 154 func ProxySetProperty(pathData *byte, pathSize int, valueData *byte, valueSize int) Status { 155 return currentHost.ProxySetProperty(pathData, pathSize, valueData, valueSize) 156 } 157 158 func ProxyGetProperty(pathData *byte, pathSize int, returnValueData **byte, returnValueSize *int) Status { 159 return currentHost.ProxyGetProperty(pathData, pathSize, returnValueData, returnValueSize) 160 } 161 162 func ProxySendLocalResponse(statusCode uint32, statusCodeDetailData *byte, 163 statusCodeDetailsSize int, bodyData *byte, bodySize int, headersData *byte, headersSize int, grpcStatus int32) Status { 164 return currentHost.ProxySendLocalResponse(statusCode, 165 statusCodeDetailData, statusCodeDetailsSize, bodyData, bodySize, headersData, headersSize, grpcStatus) 166 } 167 168 func ProxyGetSharedData(keyData *byte, keySize int, returnValueData **byte, returnValueSize *int, returnCas *uint32) Status { 169 return currentHost.ProxyGetSharedData(keyData, keySize, returnValueData, returnValueSize, returnCas) 170 } 171 172 func ProxySetSharedData(keyData *byte, keySize int, valueData *byte, valueSize int, cas uint32) Status { 173 return currentHost.ProxySetSharedData(keyData, keySize, valueData, valueSize, cas) 174 } 175 176 func ProxyRegisterSharedQueue(nameData *byte, nameSize int, returnID *uint32) Status { 177 return currentHost.ProxyRegisterSharedQueue(nameData, nameSize, returnID) 178 } 179 180 func ProxyResolveSharedQueue(vmIDData *byte, vmIDSize int, nameData *byte, nameSize int, returnID *uint32) Status { 181 return currentHost.ProxyResolveSharedQueue(vmIDData, vmIDSize, nameData, nameSize, returnID) 182 } 183 184 func ProxyDequeueSharedQueue(queueID uint32, returnValueData **byte, returnValueSize *int) Status { 185 return currentHost.ProxyDequeueSharedQueue(queueID, returnValueData, returnValueSize) 186 } 187 188 func ProxyEnqueueSharedQueue(queueID uint32, valueData *byte, valueSize int) Status { 189 return currentHost.ProxyEnqueueSharedQueue(queueID, valueData, valueSize) 190 } 191 192 func ProxyGetHeaderMapValue(mapType MapType, keyData *byte, keySize int, returnValueData **byte, returnValueSize *int) Status { 193 return currentHost.ProxyGetHeaderMapValue(mapType, keyData, keySize, returnValueData, returnValueSize) 194 } 195 196 func ProxyAddHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status { 197 return currentHost.ProxyAddHeaderMapValue(mapType, keyData, keySize, valueData, valueSize) 198 } 199 200 func ProxyReplaceHeaderMapValue(mapType MapType, keyData *byte, keySize int, valueData *byte, valueSize int) Status { 201 return currentHost.ProxyReplaceHeaderMapValue(mapType, keyData, keySize, valueData, valueSize) 202 } 203 204 func ProxyContinueStream(streamType StreamType) Status { 205 return currentHost.ProxyContinueStream(streamType) 206 } 207 208 func ProxyCloseStream(streamType StreamType) Status { 209 return currentHost.ProxyCloseStream(streamType) 210 } 211 func ProxyRemoveHeaderMapValue(mapType MapType, keyData *byte, keySize int) Status { 212 return currentHost.ProxyRemoveHeaderMapValue(mapType, keyData, keySize) 213 } 214 215 func ProxyGetHeaderMapPairs(mapType MapType, returnValueData **byte, returnValueSize *int) Status { 216 return currentHost.ProxyGetHeaderMapPairs(mapType, returnValueData, returnValueSize) 217 } 218 219 func ProxySetHeaderMapPairs(mapType MapType, mapData *byte, mapSize int) Status { 220 return currentHost.ProxySetHeaderMapPairs(mapType, mapData, mapSize) 221 } 222 223 func ProxyGetBufferBytes(bufferType BufferType, start int, maxSize int, returnBufferData **byte, returnBufferSize *int) Status { 224 return currentHost.ProxyGetBufferBytes(bufferType, start, maxSize, returnBufferData, returnBufferSize) 225 } 226 227 func ProxySetBufferBytes(bufferType BufferType, start int, maxSize int, bufferData *byte, bufferSize int) Status { 228 return currentHost.ProxySetBufferBytes(bufferType, start, maxSize, bufferData, bufferSize) 229 } 230 231 func ProxyHttpCall(upstreamData *byte, upstreamSize int, headerData *byte, headerSize int, bodyData *byte, 232 bodySize int, trailersData *byte, trailersSize int, timeout uint32, calloutIDPtr *uint32) Status { 233 return currentHost.ProxyHttpCall(upstreamData, upstreamSize, 234 headerData, headerSize, bodyData, bodySize, trailersData, trailersSize, timeout, calloutIDPtr) 235 } 236 237 func ProxyCallForeignFunction(funcNamePtr *byte, funcNameSize int, paramPtr *byte, paramSize int, returnData **byte, returnSize *int) Status { 238 return currentHost.ProxyCallForeignFunction(funcNamePtr, funcNameSize, paramPtr, paramSize, returnData, returnSize) 239 } 240 241 func ProxySetTickPeriodMilliseconds(period uint32) Status { 242 return currentHost.ProxySetTickPeriodMilliseconds(period) 243 } 244 245 func ProxySetEffectiveContext(contextID uint32) Status { 246 return currentHost.ProxySetEffectiveContext(contextID) 247 } 248 249 func ProxyDone() Status { 250 return currentHost.ProxyDone() 251 } 252 253 func ProxyDefineMetric(metricType MetricType, 254 metricNameData *byte, metricNameSize int, returnMetricIDPtr *uint32) Status { 255 return currentHost.ProxyDefineMetric(metricType, metricNameData, metricNameSize, returnMetricIDPtr) 256 } 257 258 func ProxyIncrementMetric(metricID uint32, offset int64) Status { 259 return currentHost.ProxyIncrementMetric(metricID, offset) 260 } 261 262 func ProxyRecordMetric(metricID uint32, value uint64) Status { 263 return currentHost.ProxyRecordMetric(metricID, value) 264 } 265 266 func ProxyGetMetric(metricID uint32, returnMetricValue *uint64) Status { 267 return currentHost.ProxyGetMetric(metricID, returnMetricValue) 268 }