Serializes an @element using the proper function @relicWriteBinFunc into
    a bytearray. @compress specifies whether the element should be compressed.
    @relicSizeBinFunc is used to determine the size of the serialized output.
    This is underlying implementation for serialize G1, G2, and Gt.

def _serialize(element, compress, relicSizeBinFunc, relicWriteBinFunc):
    """
    Serializes an @element using the proper function @relicWriteBinFunc into
    a bytearray. @compress specifies whether the element should be compressed.
    @relicSizeBinFunc is used to determine the size of the serialized output.
    This is underlying implementation for serialize G1, G2, and Gt.
    """
    cFlag = c_int(compress)
    size = relicSizeBinFunc(byref(element), cFlag)

    # Make an array of the correct size. 
    binArray = (c_ubyte*size)()

    # Serialize
    relicWriteBinFunc(byref(binArray), size, byref(element), cFlag)
    return bytearray(binArray)