fn long_to_value(value: i64, field: &FieldDescriptor) -> Result<Value, &'static str>{
    match field.kind(){
        // Long
        Kind::Int64 | Kind::Sint64 => Ok(Value::I64(value)),
        // Timestamp
        Kind::Message(message_descriptor) if message_descriptor.full_name() == "q.timestamp" => {
            let mut inner = DynamicMessage::new(message_descriptor.clone());
            inner.set_field_by_name("nanos", Value::I64(value));
            Ok(Value::Message(inner))
        },
        // Timespan
        Kind::Message(message_descriptor) if message_descriptor.full_name() == "q.timespan" => {
            let mut inner = DynamicMessage::new(message_descriptor.clone());
            inner.set_field_by_name("nanos", Value::I64(value));
            Ok(Value::Message(inner))
        },
        // Enum
        Kind::Enum(enum_descriptor) => {
            let range = &enum_descriptor.enum_descriptor_proto().value;
            if range[0].number.unwrap() <= value as i32 && range[range.len()-1].number.unwrap() >= value as i32{
                Ok(Value::EnumNumber(value as i32))
            }
            else{
                Err("not a reserved enum value\0")
            }
        }
        // There are no other long compatible type
        _ => Err("non-long value\0")
    }
}
/// Convert underlying long value to `Value`.
Convert underlying long value to `Value`.
Convert underlying long value to ` Value ` .
fn long_to_value(value: i64, field: &FieldDescriptor) -> Result<Value, &'static str>{
    match field.kind(){
        // Long
        Kind::Int64 | Kind::Sint64 => Ok(Value::I64(value)),
        // Timestamp
        Kind::Message(message_descriptor) if message_descriptor.full_name() == "q.timestamp" => {
            let mut inner = DynamicMessage::new(message_descriptor.clone());
            inner.set_field_by_name("nanos", Value::I64(value));
            Ok(Value::Message(inner))
        },
        // Timespan
        Kind::Message(message_descriptor) if message_descriptor.full_name() == "q.timespan" => {
            let mut inner = DynamicMessage::new(message_descriptor.clone());
            inner.set_field_by_name("nanos", Value::I64(value));
            Ok(Value::Message(inner))
        },
        // Enum
        Kind::Enum(enum_descriptor) => {
            let range = &enum_descriptor.enum_descriptor_proto().value;
            if range[0].number.unwrap() <= value as i32 && range[range.len()-1].number.unwrap() >= value as i32{
                Ok(Value::EnumNumber(value as i32))
            }
            else{
                Err("not a reserved enum value\0")
            }
        }
        // There are no other long compatible type
        _ => Err("non-long value\0")
    }
}
fn long_to_value ( value : i64 , field : & FieldDescriptor ) -> Result < Value , & ' static str > { match field . kind ( ) { // Long Kind :: Int64 | Kind :: Sint64 => Ok ( Value :: I64 ( value ) ) , // Timestamp Kind :: Message ( message_descriptor ) if message_descriptor . full_name ( ) == " " => { let mut inner = DynamicMessage :: new ( message_descriptor . clone ( ) ) ; inner . set_field_by_name ( " " , Value :: I64 ( value ) ) ; Ok ( Value :: Message ( inner ) ) } , // Timespan Kind :: Message ( message_descriptor ) if message_descriptor . full_name ( ) == " " => { let mut inner = DynamicMessage :: new ( message_descriptor . clone ( ) ) ; inner . set_field_by_name ( " " , Value :: I64 ( value ) ) ; Ok ( Value :: Message ( inner ) ) } , // Enum Kind :: Enum ( enum_descriptor ) => { let range = & enum_descriptor . enum_descriptor_proto ( ) . value ; if range [ 0 ] . number . unwrap ( ) <= value as i32 && range [ range . len ( ) - 1 ] . number . unwrap ( ) >= value as i32 { Ok ( Value :: EnumNumber ( value as i32 ) ) } else { Err ( " \0 " ) } } // There are no other long compatible type _ => Err ( " \0 " ) } }
Convert underlying long value to `Value`.
Convert underlying long value to ` Value ` .
value
i64
field
&FieldDescriptor
value
i64
field
&FieldDescriptor