Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

hit9/spp_lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Protocol Parser

Actually, this is ssdb's network protocol, and I think it can be used on other projects.

Support Lua5.1/Lua5.2/Lua5.3/LuaJIT

Protocol

Packet := Block+ '\n'
Block  := Size '\n' Data '\n'
Size   := literal_integer
Data   := string_bytes

For example:

3
set
3
key
3
val

Build

$ make 

To build for resty:

$ DFLAGS=-DSPP_LIB_PATH=resty_ssdb_spp_lua make

Usage

This package only provides parser, because packing is easy to do.

Parsing example:

local spp = require('spp_lua')
local parser = spp:new()

parser:feed("2\nok\n4\nbody\n\n")

while true do
    res = parser:get()
    if res == nil then 
        break
    else
        for i=1, #res do print(res[i]) end
    end
end
-- Output:
-- ok
-- body

API Ref

  • spp:new()
  • parser:feed(string)
  • parser:get()
  • parser:clear()

Bench

spp parser: 500000 in 2.000000s => 250000.000000ops
lua parser: 500000 in 4.000000s => 125000.000000ops

License

MIT (c) 2014, hit9 (Chao Wang).

About

SSDB Protocol Parser For Lua, Built For Speed. (Included in https://github.com/eleme/lua-resty-ssdb)

Resources

Stars

Watchers

Forks

Packages

No packages published