33package gosdk
44
55// Following is a distillation of the Envoy ABI for dynamic modules:
6- // https://github.com/envoyproxy/envoy/blob/dc2d3098ae5641555f15c71d5bb5ce0060a8015c /source/extensions/dynamic_modules/abi.h
6+ // https://github.com/envoyproxy/envoy/blob/6d9bb7d9a85d616b220d1f8fe67b61f82bbdb8d3 /source/extensions/dynamic_modules/abi.h
77//
88// Why not using the header file directly? That is because Go runtime complains
99// about passing pointers to C code on the boundary. In the following code, we replace
@@ -91,13 +91,25 @@ bool envoy_dynamic_module_callback_http_get_response_body_vector(
9191bool envoy_dynamic_module_callback_http_get_response_body_vector_size(
9292 uintptr_t filter_envoy_ptr, size_t* size);
9393
94+ // envoy_dynamic_module_type_envoy_buffer is a struct representing a buffer owned by Envoy.
95+ typedef struct {
96+ const char* ptr;
97+ size_t length;
98+ } envoy_dynamic_module_type_envoy_buffer;
99+
100+ // envoy_dynamic_module_type_module_buffer is a struct representing a buffer owned by the module.
101+ typedef struct {
102+ uintptr_t ptr;
103+ size_t length;
104+ } envoy_dynamic_module_type_module_buffer;
105+
94106#cgo noescape envoy_dynamic_module_callback_http_send_response
95- // Uncomment once https://github.com/envoyproxy/envoy/pull/39206 is merged.
96- // #cgo nocallback envoy_dynamic_module_callback_http_send_response
107+ #cgo nocallback envoy_dynamic_module_callback_http_send_response
97108void envoy_dynamic_module_callback_http_send_response(
98109 uintptr_t filter_envoy_ptr, uint32_t status_code,
99110 uintptr_t headers_vector, size_t headers_vector_size,
100- uintptr_t body, size_t body_length);
111+ envoy_dynamic_module_type_module_buffer body,
112+ envoy_dynamic_module_type_module_buffer details);
101113
102114#cgo noescape envoy_dynamic_module_callback_http_get_request_headers_count
103115#cgo nocallback envoy_dynamic_module_callback_http_get_request_headers_count
@@ -161,8 +173,8 @@ import (
161173 "unsafe"
162174)
163175
164- // https://github.com/envoyproxy/envoy/blob/dc2d3098ae5641555f15c71d5bb5ce0060a8015c /source/extensions/dynamic_modules/abi_version .h
165- var version = append ([]byte ("ca2be3b80954d2a0e22b41d033b18eff9390c30261c8ec9ffe6e6bf971f41c27 " ), 0 )
176+ // https://github.com/envoyproxy/envoy/blob/6d9bb7d9a85d616b220d1f8fe67b61f82bbdb8d3 /source/extensions/dynamic_modules/abi .h
177+ var version = append ([]byte ("4dae397a7c9ff0238d318d57ea656ce8b3fbff595787dcd7ee2ff5b79c9fe10f " ), 0 )
166178
167179//export envoy_dynamic_module_on_program_init
168180func envoy_dynamic_module_on_program_init () uintptr {
@@ -172,13 +184,11 @@ func envoy_dynamic_module_on_program_init() uintptr {
172184//export envoy_dynamic_module_on_http_filter_config_new
173185func envoy_dynamic_module_on_http_filter_config_new (
174186 _ uintptr ,
175- namePtr * C.char ,
176- nameSize C.size_t ,
177- configPtr * C.char ,
178- configSize C.size_t ,
187+ nameBuffer C.envoy_dynamic_module_type_envoy_buffer ,
188+ configBuffer C.envoy_dynamic_module_type_envoy_buffer ,
179189) uintptr {
180- name := C .GoStringN (namePtr , C .int (nameSize ))
181- config := C .GoBytes (unsafe .Pointer (configPtr ), C .int (configSize ))
190+ name := C .GoStringN (nameBuffer . ptr , C .int (nameBuffer . length ))
191+ config := C .GoBytes (unsafe .Pointer (configBuffer . ptr ), C .int (configBuffer . length ))
182192 filterConfig := NewHttpFilterConfig (name , config )
183193 if filterConfig == nil {
184194 return 0
@@ -546,8 +556,8 @@ func (e envoyFilter) SendLocalReply(statusCode uint32, headers [][2]string, body
546556 C .uint32_t (statusCode ),
547557 C .uintptr_t (headersVecPtr ),
548558 C .size_t (headersVecSize ),
549- C .uintptr_t (bodyPtr ),
550- C .size_t ( bodySize ),
559+ C.envoy_dynamic_module_type_module_buffer { ptr : C . uintptr_t (bodyPtr ), length : C . size_t ( bodySize )} ,
560+ C.envoy_dynamic_module_type_module_buffer { ptr : 0 , length : 0 }, // Empty details
551561 )
552562 runtime .KeepAlive (headers )
553563 runtime .KeepAlive (body )
0 commit comments