Networkcomms V3 's Custom object

Source: Internet
Author: User

The ability to send custom objects and encrypt the sent objects when sent, compression is an important feature of the NETWORKCOMMS v3 framework.

Refer to the source Code Exampleconsole engineering documents

The syntax for sending custom objects using the Networkcomms V3 framework is as follows:

New CustomObject ("ben"); Networkcomms.sendobject ("Message""127.0.0.1 " 10000, mycustomobject);

If you are using the Protobuf.net serializer, then the syntax for the custom object is as follows:

[Protocontract]Private classcustomobject{[Protomember (1)]     Public intAge {Get;Private Set; } [Protomember (2)]     Public stringName {Get;Private Set; } /// <summary>    ///parameterless constructor required for Protobuf/// </summary>    protectedCustomObject () {} PublicCustomObject (stringNameintAge ) {         This. Name =name;  This. Age =Age ; }}

For some classes that do not support serialization, such as serialization of the image class, some conversions are performed as follows:

[Protocontract] Public classimagewrapper{/// <summary>    ///Private Store of the image data as a byte[]///This would be populated automatically if the object is serialised/// </summary>[Protomember (1)]    Private byte[] _imagedata; /// <summary>    ///The image name/// </summary>[Protomember (2)]     Public stringImageName {Get;Set; } /// <summary>    ///The public accessor for the image. this'll be populated///automatically when the object is deserialised. /// </summary>     PublicImage Image {Get;Set; } /// <summary>    ///Private parameterless constructor required for Deserialisation/// </summary>    PrivateImagewrapper () {}/// <summary>    ///Create a new imagewrapper/// </summary>    /// <param name= "ImageName" ></param>    /// <param name= "image" ></param>     PublicImagewrapper (stringImageName, image image) {         This. ImageName =ImageName;  This. Image =image; }     /// <summary>    ///before serialising This object convert the image to binary data/// </summary>[Protobeforeserialization]Private voidSerialize () {if(Image! =NULL)        {            //We need to decide how to convert our image to its raw binary form here            using(MemoryStream InputStream =NewMemoryStream ()) {                //For basic image types The features is part of the. NET FrameworkImage.Save (InputStream, Image.rawformat); //If We wanted to include additional data processing here//such as compression, encryption etc we can still use the features provided by Networkcomms.net//e.g. see dpsmanager.getdataprocessor<lzmacompressor> ()//Store The binary image data as bytes[]_imagedata =Inputstream.toarray (); }        }    }     /// <summary>    ///When deserialising the object to convert the binary data back to an Image object/// </summary>[Protoafterdeserialization]Private voidDeserialize () {MemoryStream ms=NewMemoryStream (_imagedata); //If We added custom data processes We have the perform the reverse operations here before//trying to recreate the image object//e.g. dpsmanager.getdataprocessor<lzmacompressor> ()Image=Image.fromstream (MS); _imagedata=NULL; }}

Original: http://www.networkcomms.net/custom-objects/

Www.networkcomms.cn Finishing

Networkcomms V3 's Custom object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.