Пример #1
0
def _EncodeInt64Field(field, value):
    """Handle the special case of int64 as a string."""
    capabilities = [
        messages.Variant.INT64,
        messages.Variant.UINT64,
    ]
    if field.variant not in capabilities:
        return encoding.CodecResult(value=value, complete=False)

    if field.repeated:
        result = [str(x) for x in value]
    else:
        result = str(value)
    return encoding.CodecResult(value=result, complete=True)
Пример #2
0
def _EncodeDateField(field, value):
    """Encoder for datetime.date objects."""
    if field.repeated:
        result = [d.isoformat() for d in value]
    else:
        result = value.isoformat()
    return encoding.CodecResult(value=result, complete=True)
Пример #3
0
def _DecodeDateField(unused_field, value):
    date = datetime.datetime.strptime(value, '%Y-%m-%d').date()
    return encoding.CodecResult(value=date, complete=True)
Пример #4
0
def _DecodeInt64Field(unused_field, value):
    # Don't need to do anything special, they're decoded just fine
    return encoding.CodecResult(value=value, complete=False)
Пример #5
0
def _DecodeDateTimeField(unused_field, value):
    result = protojson.ProtoJson().decode_field(message_types.DateTimeField(1),
                                                value)
    return encoding.CodecResult(value=result, complete=True)
Пример #6
0
def _EncodeDateTimeField(field, value):
    result = protojson.ProtoJson().encode_field(field, value)
    return encoding.CodecResult(value=result, complete=True)