コード例 #1
0
ファイル: msg_spec.py プロジェクト: jddixon/fieldz
def field_spec_putter(chan, val, nnn):
    # fields are '_name', '_type', '_quantifier', '_fieldNbr', '_default'

    # write the field header
    write_raw_varint(chan, field_hdr(nnn, LEN_PLUS_TYPE))
#   print "FIELD SPEC: AFTER WRITING HEADER pos = %u" %  pos

    # write the byte count
    count = field_spec_len(val, nnn)
    write_raw_varint(chan, count)
#   print "FIELD SPEC: AFTER WRITING BYTE COUNT %u pos = %u" % (count, pos)

    # write the field's name
    L_STRING_PUT(chan, val.name, 0)             # field 0

    # write the type
    VENUM_PUT(chan, val.field_type_ndx, 1)

    # write the quantifier
    VENUM_PUT(chan, val.quantifier, 2)

    # write the field number
    VUINT32_PUT(chan, val.field_nbr, 3)

    # write the default, should there be one
    if val.default is not None:
        # XXX STUB XXX
        pass
コード例 #2
0
ファイル: msg_spec.py プロジェクト: jddixon/fieldz
def enum_pair_spec_putter(chan, val, nnn):
    # write the field header
    write_raw_varint(chan, field_hdr(nnn, LEN_PLUS_TYPE))

    # write the byte count
    count = enum_pair_spec_len(val, nnn)
    write_raw_varint(chan, count)
#   print "AFTER WRITING BYTE COUNT %u pos = %u" % (count, pos)

    # write field 0, the symbol
    L_STRING_PUT(chan, val.symbol, 0)
#   print "AFTER WRITING SYMBOL %s pos = %u" % ( val.symbol, pos)

    # write field 1, the value
    VUINT32_PUT(chan, val.value, 1)
コード例 #3
0
ファイル: msg_spec.py プロジェクト: jddixon/fieldz
def enum_spec_putter(chan, val, nnn):
    # write the field header
    write_raw_varint(chan, field_hdr(nnn, LEN_PLUS_TYPE))
#   print "AFTER WRITING HEADER pos = %u" %  pos

    # write the byte count
    count = enum_spec_len(val, nnn)
    write_raw_varint(chan, count)
#   print "AFTER WRITING BYTE COUNT %u pos = %u" % (count, pos)

    # write the enum's name
    L_STRING_PUT(chan, val.name, 0)             # field 0

    # write the pairs
    for pair in val:
        enum_pair_spec_putter(chan, pair, 1)   # field 1 instances
コード例 #4
0
ファイル: msg_spec.py プロジェクト: jddixon/fieldz
def msg_spec_putter(chan, val, nnn):
    # fields are  protocol, name, fields, enum=None

    # write the field header
    write_raw_varint(chan, field_hdr(nnn, LEN_PLUS_TYPE))
    print("MSG SPEC: AFTER WRITING HEADER pos = %u" % chan.position)

    # write the byte count
    count = msg_spec_len(val, nnn)
    write_raw_varint(chan, count)
    print("MSG SPEC: AFTER WRITING BYTE COUNT %u pos = %u" % (
        count, chan.position))

    # write the spec's name
    L_STRING_PUT(chan, val.name, 0)                 # field 0

    # write the fields
    for field in val:
        field_spec_putter(chan, field, 1)          # field 1 instances

    # write the enum, should there be one
    if val.enums is not None and val.enums != []:
        for enum in val.enums:
            enum_spec_putter(chan, enum, 2)         # yup, field 2
コード例 #5
0
ファイル: msg_impl.py プロジェクト: jddixon/fieldz
    def write(self, chan, nnn):
        """
        n is the msg's field number OR regID
        """
        write_field_hdr(chan, nnn, LEN_PLUS_TYPE)   # write the field header
        msg_len = self._wire_len()         # then the unprefixed length
        write_raw_varint(chan, msg_len)

        # XXX DEBUG
        print("ENTERING MsgImpl.write FIELD NBR %u, MSG LEN IS %u; AFTER WRITING HDR OFFSET  %u" % (
            nnn, msg_len, chan.position))

        # XXX This only makes sense for simple messages all of whose
        # fields are required and so have only a single instance
        for field in self._fields:      # these are instances with a value attr

            # CLASS-LEVEL SLOTS are '_name', '_fType', '_quantifier',
            #                       '_fieldNbr', '_default',]
            # INSTANCE-LEVEL SLOT is '_value'

            f_name = field._name
            f_nbr = field.field_nbr
            f_quant = field.quantifier          # NEXT HURDLE
            field_type = field.field_type
            value = field.value
            default = field.default

            if f_quant == Q_REQUIRED or f_quant == Q_OPTIONAL:
                if field_type > 23:
                    # DEBUG
                    reg = self.msg_spec.reg
                    print("RECURSING TO WRITE FIELD %u TYPE %s" % (
                        f_nbr, reg.reg_id2name(field_type)))
                    # END
                    value.write(chan, f_nbr)
                else:
                    # DEBUG
                    display_val = value
                    if field_type == FieldTypes.L_STRING and len(
                            display_val) > 16:
                        display_val = display_val[:16] + '...'
                    print("WRITING FIELD %u TYPE %u VALUE %s" % (
                        f_nbr, field_type, display_val))
                    # END
                    T_PUT_FUNCS[field_type](chan, value, f_nbr)
            elif f_quant == Q_PLUS or f_quant == Q_STAR:
                v_list = value
                for varint_ in v_list:
                    # WORKING HERE
                    if field_type > 23:
                        # DEBUG
                        reg = self.msg_spec.reg
                        print("RECURSING TO WRITE FIELD %u TYPE %s" % (
                            f_nbr, reg.reg_id2name(field_type)))
                        # END
                        # this function recursing
                        varint_.write(chan, f_nbr)
                    else:
                        T_PUT_FUNCS[field_type](chan, varint_, f_nbr)
            else:
                raise RuntimeError(
                    "field '%s' has unknown quantifier '%s'" % (
                        f_name, Q_NAMES[f_quant]))  # GEEP