module hunt.imf.protocol.protobuf.ProtobufEncoder; import hunt.net.codec.Encoder; import hunt.net.Connection; import hunt.imf.ParserBase; import hunt.imf.MessageBuffer; import hunt.collection.ByteBuffer; import hunt.collection.BufferUtils; import hunt.Exceptions; import std.bitmanip; import std.conv; import std.stdio; import std.stdint; class ProtobufEncoder : ParserBase , Encoder { override void encode(Object message, Connection connection) { auto msg = cast(MessageBuffer)message; ubyte[] msgBody = msg.message; if (msgBody.length > 2147483647 || msgBody.length < 0 ) { return; } ubyte[8] u1 = nativeToBigEndian(msg.authId); ubyte[8] u2 = nativeToBigEndian(msg.messageId); ubyte[4] u3 = nativeToBigEndian(cast(int32_t)msgBody.length); connection.write(u1 ~ u2 ~ u3 ~ msgBody); } void setBufferSize(int size) { } }