Giter VIP home page Giter VIP logo

insidepacketprocessor's Introduction

InsidePacketProcessor

A serializer that automatically deserializes a Stream to the correct type! Uses protobuf-net internally.

Notes

  • As it uses protobuf-net internally, you will have to include the appropriate attributes inside the class / struct you're registering! More info can be found @ https://github.com/protobuf-net/protobuf-net ! Examples can be found in Tests/Test c;

  • As InsidePacketProcessor is a struct, it is passed by copy by default! This is however not a huge issue ( Usability wise ), as the processor does not rely on any internal state that would be desynced by copying!

Notable features include

  • Ability to Serialize / Deserialize classes / structs without public parameterless constructor ( Apparently this is a limitation of protobuf-net )

  • Zero-garbage! This library doesn't allocate anything that is tracked by the GC! ( This is assuming that you use .SubscribeToTypeReusable() for classes! )

  • Easy to use! Just register the appropriate type with .SubscribeToType() or its reusable variant!

APIs:

  • InsidePacketProcessor.Create(int InitSize = 10): Instantiates an instance of the Processor!

    InitSize: The initial size of Processor! This should ideally be the number of types you plan to subscribe to, though it is fine if the subscription count exceeds the initial size...resizing just happens!

  • Serialize(ref T Item, Stream Stream, int WriteIndex = 0): Attempt to serialize a specific class / struct into a Stream

    Item: The class / struct to serialize

    Stream: The stream to write to

    WriteIndex: An optional parameter to specify the Stream position to start writing to. This is by default 0.

  • Deserialize(Stream Stream, int ReadIndex = 0): Attempt to deserialize a specific type by reading from the specified Stream! If the type is Subscribed to ( Using .SubscribeToType() or its reusable variant ), it would invoke the registered anonymous function!

    Stream: The stream to read from

    ReadIndex: An optional parameter to specify the Stream position to start reading from. This is by default 0.

  • SubscribeToType(PacketProcessorAct Act): Allows you to subscribe to a specific type with an anonymous function, such that when .Deserialize() deserializes to the subscribed type, it would invoke the supplied anonymous function!

    PacketProcessorAct Act: The anonymous function!

  • SubscribeToTypeReusable(PacketProcessorAct Act): Reusable variant of the above subscribe method! This is useful if you wish to reuse an instance of a class instead of instantiating a new one when deserialization occurs! This is useful for reducing GC pressure...Consequentially, the class instance's properties may be overwritten on next deserialize!

    PacketProcessorAct Act: The anonymous function!

  • UnsubType(): Unsubscribes the type, and consequentially, previously subscribed anonymous function would no longer be invoked on deserialization of the type.

  • UnsubAllTypes(): Unsubscribes all subscribed types!

  • Dispose(): Release ALL resources used by the Processor! It is paramount to call this after you're done using the Processor to prevent memory leaks!

insidepacketprocessor's People

Contributors

budgetdevv avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.