Beispiel #1
0
    }                                       // What the picture is

    public byte[] ToDataStream()
    {
        byte[] contentBuffer = null;
        switch (TypeOfByte)
        {
        case ByteCodes.sound:
            contentBuffer = new byte[SoundData.Length + 5];
            SoundData.CopyTo(contentBuffer, 5);
            break;

        case ByteCodes.Position:
            contentBuffer = new byte[PositionData.Length + 5];
            PositionData.CopyTo(contentBuffer, 5);
            break;

        case ByteCodes.PictureData:
            contentBuffer = new byte[PictureData.Length + 5];
            PictureData.CopyTo(contentBuffer, 5);
            break;
        }
        ByteTypeCode = (byte)(int)TypeOfByte;
        int Length = contentBuffer.Length - 5;

        byte[] byteLength = BitConverter.GetBytes(Length);

        // assign the first 5 bytes as the type and length checksum ( minus 5 )
        contentBuffer[0] = ByteTypeCode;
        contentBuffer[1] = byteLength[0];
        contentBuffer[2] = byteLength[1];
        contentBuffer[3] = byteLength[2];
        contentBuffer[4] = byteLength[3];

        return(contentBuffer);
    }