Skip to content

Instantly share code, notes, and snippets.

@nulldatamap
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save nulldatamap/871810fca10abe579af2 to your computer and use it in GitHub Desktop.

Select an option

Save nulldatamap/871810fca10abe579af2 to your computer and use it in GitHub Desktop.

This template:

/*
packets
${name} ${id} %{packet_fields for fields}.
?{if not last:$n}
.

packet_fields
?{if first:$n}  ${value} ${key}$n
.

@BODY

%{packets}

*/

Given this data ( It's a Python data structure ):

[ {'fields': {'token': 'str'
             , 'version': 'u32'
             , 'magic': 'u32'}
  , 'name': 'Handshake'
  , 'id': 255}

, {'fields': {'error_id': 'u32'
             , 'error_msg': 'str?'}
  , 'name': 'Error'
  , 'id': 0}

, {'fields': {}
  , 'name': 'Okay'
  , 'id': 1}

, {'fields': {'data': 'i32'}
  , 'name': 'Ping'
  , 'id': 2}

, {'fields': {'reason': 'str?'}
  , 'name': 'Kill'
  , 'id': 3}
]

Which was parsed from ( Protocol Defition Format ):

Handshake 0xFF
  u32 magic
  u32 version
  str token
.

Error 0
  u32 error_id
  str? error_msg
.

Okay 1 .

Ping 2
  i32 data
.

# Actuall not sure if to keep this message or
# ust use Error for that. ( see 'errors.md' and 'protocol.md' )
Kill 3
  str? reason
.

Produced this:

Handshake 255 
  str token
  u32 version
  u32 magic
.

Error 0 
  u32 error_id
  str? error_msg
.

Okay 1 .

Ping 2 
  i32 data
.

Kill 3 
  str? reason
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment