hdbconnect_impl/types_impl/lob/char_lob_slice.rs
1/// Return value when reading a slice with `CLob::read_slice()` or `NCLob::read_slice()`.
2///
3/// Both methods allow specifying the `offset` and the `length` of the requested slice.
4///
5/// * `CLob::read_slice()` interprets `offset` and `length` as numbers of bytes, applied to the
6/// HANA-internally used CESU8-encoding, where a unicode codepoint needs between 1 and 6 bytes.
7///
8/// If the specified boundaries of the slice do not coincide with the
9/// begin or end of a unicode-codepoint, then it will begin and/or end with a byte
10/// sequence that cannot be converted into UTF-8, the unicode-encoding used by rust's `String`.
11/// `CharLobSlice::prefix` and/or `CharLobSlice::postfix` then contain these 1-5 extra bytes.
12///
13/// * `NCLob::read_slice()` interprets `offset` and `length` as numbers of unicode characters,
14/// where the following rule is applied:
15///
16/// * a unicode codepoint in BMP-0 (which is represented as 1, 2, or 3 bytes) counts as 1
17///
18/// * a unicode codepoint in BMP-1 (which is represented as a pair of two surrogates,
19/// each of which is a 3-byte sequence) counts as 2.
20///
21/// If the specified boundaries of the slice do not coincide with the
22/// begin or end of a unicode-codepoint, i.e. if the slice begins with a second surrogate or ends
23/// with a first surrogate, then
24/// `CharLobSlice::prefix` and/or `CharLobSlice::postfix` will contain these 3 extra bytes.
25#[derive(Clone, Debug)]
26pub struct CharLobSlice {
27 /// If relevant, contains bytes at the begin of the slice from an incomplete unicode-codepoint.
28 pub prefix: Option<Vec<u8>>,
29 /// The main part of the slice.
30 pub data: String,
31 /// If relevant, contains bytes at the end of the slice from an incomplete unicode-codepoint.
32 pub postfix: Option<Vec<u8>>,
33}