Skip to content

aleclarson/lua-json-rpc

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

lua-json-rpc v0.0.1

JSON events for long-lived connections.

local rpc = require('json-rpc')

-- Inject your JSON module
rpc.JSON = require('json')

-- Encode an event message
local msg = rpc.encode('event', {1, 2, 3})
print(msg) -- '14;event;[1,2,3];'

-- Create a message decoder
local decode = rpc.decoder(function(name, data)
  print(name) -- 'event'
  print(data) -- {1, 2, 3}
end)

-- Decode an event message
decode(msg)

-- Decode an event message across several chunks
local chunks = { msg:sub(1, #msg-4), msg:sub(#msg-3) }
for i, chunk in ipairs(chunks) do
  decode(chunk)
end

-- Decode multiple messages in one chunk
decode(msg .. rpc.encode('foo') .. rpc.encode('bar'))
  • the event name cannot contain semi-colons or be empty
  • the event data is optional

Other Implementations

About

JSON events for long-lived connections

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages