Communication related to custom TPC plugin development


I want to proxy an RPC interface based on TCP coordination.
and implement the authentication function in the pre-reading phase in Kong gateway, I don’t know if this idea can be implemented, please give me some relevant reference or some direction to guide me, currently I get a data of userdata data type through ngx.req.socket() API, but I don’t know how to use lua to parse this data type, I Is the current direction the right one?