Giter Site home page Giter Site logo

photonserializer's Introduction

header

Skills

WEB

     
       

GAME

   

PROGRAMMING

     

photonserializer's People

Contributors

arcueidd avatar ms-lima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

uurha

photonserializer's Issues

Custom serialization for byte[]

Hello, thanks for creating this serializer. It's very helpful, could you please help me with extending your serializer. I want to add serializing for byte[], but it gives me error about lenght of byte array, but I done this same as int[].

public static void Serialize(byte value, ref byte[] bytes)
{
    byte[] _bytes = BitConverter.GetBytes(value);
    if (BitConverter.IsLittleEndian)
        Array.Reverse(_bytes);

    JoinBytes(ref bytes, _bytes);
}
        
public static void Serialize(byte[] values, ref byte[] bytes)
{
    int length = values == null ? 0 : values.Length;
    if (length > 0)
    {
        Serialize(length, ref bytes);
        for (int i = 0; i < values.Length; i++)
        {
            Serialize(values[i], ref bytes);
        }
    }
    else
    {
        Serialize(0, ref bytes);
    }
}

public static byte DeserializeByte(byte[] bytes, ref int offset)
{
    byte[] _bytes = new byte[4];
    Array.Copy(bytes, offset, _bytes, 0, 4);

    if (BitConverter.IsLittleEndian)
        Array.Reverse(_bytes);

    offset += 4;
    return (byte)BitConverter.ToInt16(_bytes, 0);

    // int, float, bool vecot3, ve2 ,qua, string
}

public static byte[] DeserializeByteArray(byte[] bytes, ref int offset)
{
    int length = DeserializeInt(bytes, ref offset);
    if (length > 0)
    {
        byte[] array = new byte[length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = DeserializeByte(bytes, ref offset);
        }

        return array;
    }

    return new byte[0];
}

Package Manager

Good day, do you mind if I'll prepare your asset for package released on https://openupm.com? I wanna create Photon RaiseEvent Bus system, and I wanna add dependency onto your package to keep you as creator of this serializer.

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.