packet-maker 0.4.1

Packet encoder and decoder generator


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Create packet encoders and decoders without writing any encode or decode method.

DUB Package codecov Build Status

import packetmaker;

class MyPacket : PacketImpl!(Endian.bigEndian, ubyte, varuint) {

	enum ubyte ID = 1;

	uint integer;
	ubyte[] array;
	@LittleEndian short le;

	mixin Make;

}

MyPacket packet = new MyPacket();
packet.integer = 12;
packet.array = [1, 2, 3];
packet.le = 1;

assert(packet.autoEncode() == [

	// `ID` constant encoded as an unsigned byte as specified in the
	// second field of PacketImpl
	1,
	
	// `integer` field encoded as big endian as specified in the first
	// field of PacketImpl
	0, 0, 0, 12,
	
	// `array` field's length encoded as unsigned varint, as specified
	// in the third field of PacketImpl
	3,
	
	// content of `array`, a sequence of 3 bytes
	1, 2, 3,
	
	// content of `le` encoded as little endian because the @LittleEndian
	// attribute overrides the default endianness specified in PacketImpl
	1, 0,
	
]);
Authors:
  • Kripth
Dependencies:
xbuffer
Versions:
0.4.1 2018-Mar-31
0.4.0 2018-Mar-21
0.3.0 2018-Mar-15
0.2.0 2018-Mar-12
0.1.1 2018-Mar-11
Show all 7 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 1 downloads this month

  • 244 downloads total

Score:
0.6
Short URL:
packet-maker.dub.pm