コード例 #1
0
def tag_message(msg):
    """
    Insert serialization tag in msg
    where we anticipate a fragmentation.

    Note: fragmentation has many rules, i.e.
    seemingly fragmentation does not break words.
    But if you have ({ without whitespace- then fragmentation
    can happen along those. 

    Documentation is also non-existent, 
    maybe look in GSM standard
    """
    MSG_LEN = 160
    #Tag Format is @@XXXX -> can order upto 9999 messages
    # = 9999 bytes
    TAG_LEN = 6
    #The step size while iterating over msg
    STEP = MSG_LEN - TAG_LEN

    #Get tag
    # index -> @@XXXX
    get_tag = lambda i: "@@" + str(i).zfill(4)

    #Get tagged chunk
    get_tagged = lambda i, chunk: get_tag(i) + chunk

    offset = STEP - len(prologue)

    chunks = []
    for i, chunk in enumerate(chunk_iter_offset(msg, size=STEP,
                                                offset=offset)):
        #print "byte_len is {}\n{}\n{}\n{}\n\n".format(byte_len(chunk), "-"*40, chunk, "="*40)
        chunks.append(get_tagged(i, chunk))

    #Use an end-tag to indicate end,
    #and track total number of chars sent
    #end tag format @@EXXXX -> XXXX=string len (not byte length)
    #of untagged message
    #can be from 1 to 9999*160 ~ 1,600,000
    tagged_msg = "".join(chunks)
    tagged_msg = tagged_msg + "@@E" + str(len(msg)) + "E@@"

    return tagged_msg
コード例 #2
0
ファイル: getData.py プロジェクト: spandanb/ipos
def tag_message(msg):
    """
    Insert serialization tag in msg
    where we anticipate a fragmentation.

    Note: fragmentation has many rules, i.e.
    seemingly fragmentation does not break words.
    But if you have ({ without whitespace- then fragmentation
    can happen along those. 

    Documentation is also non-existent, 
    maybe look in GSM standard
    """
    MSG_LEN = 160
    #Tag Format is @@XXXX -> can order upto 9999 messages
    # = 9999 bytes
    TAG_LEN = 6
    #The step size while iterating over msg
    STEP = MSG_LEN - TAG_LEN

    #Get tag
    # index -> @@XXXX
    get_tag = lambda i:  "@@" +  str(i).zfill(4) 
    
    #Get tagged chunk
    get_tagged = lambda i, chunk: get_tag(i) + chunk
    
    offset = STEP - len(prologue)
    
    chunks = []
    for i, chunk in enumerate(chunk_iter_offset(msg, size=STEP, offset=offset)):
        #print "byte_len is {}\n{}\n{}\n{}\n\n".format(byte_len(chunk), "-"*40, chunk, "="*40)
        chunks.append(get_tagged(i, chunk))

    #Use an end-tag to indicate end, 
    #and track total number of chars sent 
    #end tag format @@EXXXX -> XXXX=string len (not byte length) 
    #of untagged message
    #can be from 1 to 9999*160 ~ 1,600,000 
    tagged_msg = "".join(chunks)
    tagged_msg =  tagged_msg + "@@E" + str(len(msg)) + "E@@"

    return tagged_msg
コード例 #3
0
ファイル: streamData.py プロジェクト: spandanb/ipos
def test2():
    data = "012345678[9"
    for sms in chunk_iter_offset(data, size=5, offset=3):
        print '"{}", byte_len is {}'.format(sms, byte_len(sms))
        print "------------------"
コード例 #4
0
def test2():
    data = "012345678[9"
    for sms in chunk_iter_offset(data, size=5, offset=3):
        print '"{}", byte_len is {}'.format(sms, byte_len(sms))
        print "------------------"