diff options
author | Jason Wolfe <mypetclone@gmail.com> | 2018-05-08 11:30:31 +0900 |
---|---|---|
committer | Paul Masurel <paul.masurel@gmail.com> | 2018-05-07 19:30:31 -0700 |
commit | 8e343b1ca3915b54134214c60b45d47effce60d6 (patch) | |
tree | 82c99c8fc66729828739233694c15b9fc3a40bd3 /src/schema/value.rs | |
parent | 99c0b840367c13211c9c9931a249df57f94ce1fd (diff) |
Add fast field for associating arbitrary bytes to a document (#275)
* Add fast field for associating arbitrary bytes to a document
* Fix unused macro_use warning
* Improvements from code review
* Make BytesFastFieldWriter public
* Fix json parsing validation failure
* Add bytes fast field to CHANGELOG.md
* Fix compile errors from merge
* Support merging
* Address misc code review comments
* Fix comments from CR
Diffstat (limited to 'src/schema/value.rs')
-rw-r--r-- | src/schema/value.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/schema/value.rs b/src/schema/value.rs index bae96d8..f5ce151 100644 --- a/src/schema/value.rs +++ b/src/schema/value.rs @@ -15,6 +15,8 @@ pub enum Value { I64(i64), /// Hierarchical Facet Facet(Facet), + /// Arbitrarily sized byte array + Bytes(Vec<u8>), } impl Serialize for Value { @@ -27,6 +29,7 @@ impl Serialize for Value { Value::U64(u) => serializer.serialize_u64(u), Value::I64(u) => serializer.serialize_i64(u), Value::Facet(ref facet) => facet.serialize(serializer), + Value::Bytes(ref bytes) => serializer.serialize_bytes(bytes), } } } @@ -131,6 +134,12 @@ impl<'a> From<Facet> for Value { } } +impl From<Vec<u8>> for Value { + fn from(bytes: Vec<u8>) -> Value { + Value::Bytes(bytes) + } +} + mod binary_serialize { use super::Value; use common::BinarySerializable; @@ -141,6 +150,7 @@ mod binary_serialize { const U64_CODE: u8 = 1; const I64_CODE: u8 = 2; const HIERARCHICAL_FACET_CODE: u8 = 3; + const BYTES_CODE: u8 = 4; impl BinarySerializable for Value { fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> { @@ -161,6 +171,10 @@ mod binary_serialize { HIERARCHICAL_FACET_CODE.serialize(writer)?; facet.serialize(writer) } + Value::Bytes(ref bytes) => { + BYTES_CODE.serialize(writer)?; + bytes.serialize(writer) + } } } fn deserialize<R: Read>(reader: &mut R) -> io::Result<Self> { @@ -179,6 +193,7 @@ mod binary_serialize { Ok(Value::I64(value)) } HIERARCHICAL_FACET_CODE => Ok(Value::Facet(Facet::deserialize(reader)?)), + BYTES_CODE => Ok(Value::Bytes(Vec::<u8>::deserialize(reader)?)), _ => Err(io::Error::new( io::ErrorKind::InvalidData, format!("No field type is associated with code {:?}", type_code), |