Switch back to prefix-format binary annotations

This commit is contained in:
Tony Garnock-Jones 2023-10-15 00:33:41 +02:00
parent b7a2acf65b
commit 3b89cbe880
32 changed files with 645 additions and 615 deletions

View File

@ -3,6 +3,7 @@ For a value `V`, we write `«V»` for the binary encoding of `V`.
«#f» = [0x80] «#f» = [0x80]
«#t» = [0x81] «#t» = [0x81]
«@W V» = [0x85] ++ «W» ++ «V»
«#!V» = [0x86] ++ «V» «#!V» = [0x86] ++ «V»
«V» if V ∈ Float = [0x87, 0x04] ++ binary32(V) «V» if V ∈ Float = [0x87, 0x04] ++ binary32(V)
@ -29,9 +30,3 @@ The functions `binary32(F)` and `binary64(D)` yield big-endian 4- and
The function `intbytes(x)` is a big-endian two's-complement signed binary representation of The function `intbytes(x)` is a big-endian two's-complement signed binary representation of
`x`, taking exactly as many whole bytes as needed to unambiguously identify the value and its `x`, taking exactly as many whole bytes as needed to unambiguously identify the value and its
sign. In particular, `intbytes(0)` is the empty byte sequence. sign. In particular, `intbytes(0)` is the empty byte sequence.
**Annotations.** To annotate an encoded value `«V»` (which *MUST NOT* itself already be
annotated) with some sequence of `Value`s `V_1...V_m` (which *MUST* be non-empty),
surround `«V»` as follows:
«@V_1...@V_m V» = [0xBF] ++ «V» ++ «V_1» ++...++ «V_m» ++ [0x84]

View File

@ -219,6 +219,7 @@ typedef enum preserves_binary_format_tag {
PRESERVES_BINARY_FORMAT_TAG_FALSE = 0x80, PRESERVES_BINARY_FORMAT_TAG_FALSE = 0x80,
PRESERVES_BINARY_FORMAT_TAG_TRUE = 0x81, PRESERVES_BINARY_FORMAT_TAG_TRUE = 0x81,
PRESERVES_BINARY_FORMAT_TAG_END = 0x84, PRESERVES_BINARY_FORMAT_TAG_END = 0x84,
PRESERVES_BINARY_FORMAT_TAG_ANNOTATION = 0x85,
PRESERVES_BINARY_FORMAT_TAG_EMBEDDED = 0x86, PRESERVES_BINARY_FORMAT_TAG_EMBEDDED = 0x86,
PRESERVES_BINARY_FORMAT_TAG_IEEE754 = 0x87, PRESERVES_BINARY_FORMAT_TAG_IEEE754 = 0x87,
@ -231,8 +232,6 @@ typedef enum preserves_binary_format_tag {
PRESERVES_BINARY_FORMAT_TAG_SEQUENCE = 0xB5, PRESERVES_BINARY_FORMAT_TAG_SEQUENCE = 0xB5,
PRESERVES_BINARY_FORMAT_TAG_SET = 0xB6, PRESERVES_BINARY_FORMAT_TAG_SET = 0xB6,
PRESERVES_BINARY_FORMAT_TAG_DICTIONARY = 0xB7, PRESERVES_BINARY_FORMAT_TAG_DICTIONARY = 0xB7,
PRESERVES_BINARY_FORMAT_TAG_ANNOTATION = 0xBF,
} preserves_binary_format_tag_t; } preserves_binary_format_tag_t;
PRESERVES_OUTOFLINE PRESERVES_OUTOFLINE
@ -242,6 +241,7 @@ PRESERVES_OUTOFLINE
case PRESERVES_BINARY_FORMAT_TAG_FALSE: return "FALSE"; case PRESERVES_BINARY_FORMAT_TAG_FALSE: return "FALSE";
case PRESERVES_BINARY_FORMAT_TAG_TRUE: return "TRUE"; case PRESERVES_BINARY_FORMAT_TAG_TRUE: return "TRUE";
case PRESERVES_BINARY_FORMAT_TAG_END: return "END"; case PRESERVES_BINARY_FORMAT_TAG_END: return "END";
case PRESERVES_BINARY_FORMAT_TAG_ANNOTATION: return "ANNOTATION";
case PRESERVES_BINARY_FORMAT_TAG_EMBEDDED: return "EMBEDDED"; case PRESERVES_BINARY_FORMAT_TAG_EMBEDDED: return "EMBEDDED";
case PRESERVES_BINARY_FORMAT_TAG_IEEE754: return "IEEE754"; case PRESERVES_BINARY_FORMAT_TAG_IEEE754: return "IEEE754";
case PRESERVES_BINARY_FORMAT_TAG_SIGNED_INTEGER: return "SIGNED_INTEGER"; case PRESERVES_BINARY_FORMAT_TAG_SIGNED_INTEGER: return "SIGNED_INTEGER";
@ -252,7 +252,6 @@ PRESERVES_OUTOFLINE
case PRESERVES_BINARY_FORMAT_TAG_SEQUENCE: return "SEQUENCE"; case PRESERVES_BINARY_FORMAT_TAG_SEQUENCE: return "SEQUENCE";
case PRESERVES_BINARY_FORMAT_TAG_SET: return "SET"; case PRESERVES_BINARY_FORMAT_TAG_SET: return "SET";
case PRESERVES_BINARY_FORMAT_TAG_DICTIONARY: return "DICTIONARY"; case PRESERVES_BINARY_FORMAT_TAG_DICTIONARY: return "DICTIONARY";
case PRESERVES_BINARY_FORMAT_TAG_ANNOTATION: return "ANNOTATION";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
}); });
@ -312,7 +311,6 @@ typedef enum preserves_error_code {
PRESERVES_END_UNEXPECTED_END, PRESERVES_END_UNEXPECTED_END,
PRESERVES_END_DICTIONARY_MISSING_VALUE, PRESERVES_END_DICTIONARY_MISSING_VALUE,
PRESERVES_END_RECORD_MISSING_LABEL, PRESERVES_END_RECORD_MISSING_LABEL,
PRESERVES_END_ANNOTATION_TOO_SHORT,
PRESERVES_END_VARINT_TOO_BIG, PRESERVES_END_VARINT_TOO_BIG,
PRESERVES_END_INVALID_UTF8, PRESERVES_END_INVALID_UTF8,
PRESERVES_END_INVALID_TAG, PRESERVES_END_INVALID_TAG,
@ -329,7 +327,6 @@ PRESERVES_OUTOFLINE(char const *preserves_error_code_name(preserves_error_code_t
case PRESERVES_END_UNEXPECTED_END: return "UNEXPECTED_END"; case PRESERVES_END_UNEXPECTED_END: return "UNEXPECTED_END";
case PRESERVES_END_DICTIONARY_MISSING_VALUE: return "DICTIONARY_MISSING_VALUE"; case PRESERVES_END_DICTIONARY_MISSING_VALUE: return "DICTIONARY_MISSING_VALUE";
case PRESERVES_END_RECORD_MISSING_LABEL: return "RECORD_MISSING_LABEL"; case PRESERVES_END_RECORD_MISSING_LABEL: return "RECORD_MISSING_LABEL";
case PRESERVES_END_ANNOTATION_TOO_SHORT: return "ANNOTATION_TOO_SHORT";
case PRESERVES_END_VARINT_TOO_BIG: return "VARINT_TOO_BIG"; case PRESERVES_END_VARINT_TOO_BIG: return "VARINT_TOO_BIG";
case PRESERVES_END_INVALID_UTF8: return "INVALID_UTF8"; case PRESERVES_END_INVALID_UTF8: return "INVALID_UTF8";
case PRESERVES_END_INVALID_TAG: return "INVALID_TAG"; case PRESERVES_END_INVALID_TAG: return "INVALID_TAG";
@ -394,19 +391,23 @@ PRESERVES_OUTOFLINE
- repr=PRESERVES_ESCAPED -> len, data._unsigned as absolute offset within input to utf-8 bytes - repr=PRESERVES_ESCAPED -> len, data._unsigned as absolute offset within input to utf-8 bytes
that need Symbol-style backslash-escapes interpreted that need Symbol-style backslash-escapes interpreted
PRESERVES_RECORD, PRESERVES_SEQUENCE, PRESERVES_SET, PRESERVES_DICTIONARY, PRESERVES_ANNOTATION: PRESERVES_RECORD, PRESERVES_SEQUENCE, PRESERVES_SET, PRESERVES_DICTIONARY:
- repr==PRESERVES_REPR_NONE, - repr==PRESERVES_REPR_NONE,
- len counts number of items: - len counts number of items:
- PRESERVES_RECORD -> number of fields plus one (for the label) - PRESERVES_RECORD -> number of fields plus one (for the label)
- PRESERVES_SEQUENCE -> number of items - PRESERVES_SEQUENCE -> number of items
- PRESERVES_SET -> number of items - PRESERVES_SET -> number of items
- PRESERVES_DICTIONARY -> twice the number of key-value pairs - PRESERVES_DICTIONARY -> twice the number of key-value pairs
- PRESERVES_ANNOTATION -> number of annotations plus one (for the underlying item)
- for PRESERVES_ANNOTATION, the annotated item will not be a PRESERVES_ANNOTATION
- data._unsigned as relative offset within index to next item, - data._unsigned as relative offset within index to next item,
starting from this entry; zero means "no end known" starting from this entry; zero means "no end known"
PRESERVES_EMBEDDED: repr==PRESERVES_REPR_NONE, len==0, following item is the embedded value PRESERVES_EMBEDDED: repr==PRESERVES_REPR_NONE, len==0, following item is the embedded value
PRESERVES_ANNOTATION:
- repr==PRESERVES_REPR_NONE,
- len counts number of annotations,
- data._unsigned as relative offset within index to annotated
item, starting from this entry; zero means "no end known"
- the annotated item will not be a PRESERVES_ANNOTATION
PRESERVES_END_MARKER: repr==PRESERVES_REPR_NONE, len==0, data._err PRESERVES_END_MARKER: repr==PRESERVES_REPR_NONE, len==0, data._err
*/ */
@ -436,6 +437,7 @@ typedef struct preserves_reader {
size_t stack_top; /* ascending empty */ size_t stack_top; /* ascending empty */
size_t input_pos; /* ascending full */ size_t input_pos; /* ascending full */
size_t index_pos; /* ascending empty */ size_t index_pos; /* ascending empty */
bool annotation_tag_seen;
} preserves_reader_t; } preserves_reader_t;
typedef struct preserves_reader_result { typedef struct preserves_reader_result {
@ -455,6 +457,7 @@ PRESERVES_INLINE preserves_reader_t preserves_create_reader(void) {
.stack_top = 0, .stack_top = 0,
.input_pos = 0, .input_pos = 0,
.index_pos = 0, .index_pos = 0,
.annotation_tag_seen = false,
}; };
} }
@ -465,6 +468,7 @@ PRESERVES_OUTOFLINE(void preserves_free_reader(preserves_reader_t *r), {
r->stack_top = 0; r->stack_top = 0;
r->input_pos = 0; r->input_pos = 0;
r->index_pos = 0; r->index_pos = 0;
r->annotation_tag_seen = false;
}); });
PRESERVES_IMPLEMENTATION_CHUNK PRESERVES_IMPLEMENTATION_CHUNK
@ -534,6 +538,11 @@ PRESERVES_IMPLEMENTATION_CHUNK
return base; return base;
} }
static inline bool _preserves_reader_in_annotations(preserves_reader_t *r) {
return (r->stack_top > 0) &&
(_preserves_reader_stack_top_entry(r)->type == PRESERVES_ANNOTATION);
}
static inline void _preserves_reader_inc_collection_len(preserves_reader_t *r, size_t *count_ptr) { static inline void _preserves_reader_inc_collection_len(preserves_reader_t *r, size_t *count_ptr) {
if (r->stack_top > 0) { if (r->stack_top > 0) {
check_for_embedded: check_for_embedded:
@ -554,6 +563,10 @@ PRESERVES_IMPLEMENTATION_CHUNK
static inline preserves_index_entry_t *_preserves_reader_emit_entry(preserves_reader_t *r, static inline preserves_index_entry_t *_preserves_reader_emit_entry(preserves_reader_t *r,
size_t *count_ptr, size_t *count_ptr,
preserves_index_entry_t e) { preserves_index_entry_t e) {
if (!r->annotation_tag_seen && _preserves_reader_in_annotations(r)) {
/* printf("(popping annotation collector)\n"); */
_preserves_reader_finish_seq(r);
}
if (count_ptr != NULL) { if (count_ptr != NULL) {
_preserves_reader_inc_collection_len(r, count_ptr); _preserves_reader_inc_collection_len(r, count_ptr);
} }
@ -566,6 +579,8 @@ PRESERVES_IMPLEMENTATION_CHUNK
*ix = e; *ix = e;
r->index_pos++; r->index_pos++;
r->annotation_tag_seen = false;
return ix; return ix;
} }
@ -757,7 +772,7 @@ PRESERVES_IMPLEMENTATION_CHUNK
PRESERVES_INLINE preserves_index_entry_t *preserves_skip_annotations(preserves_index_entry_t *ix) { PRESERVES_INLINE preserves_index_entry_t *preserves_skip_annotations(preserves_index_entry_t *ix) {
if (ix == NULL) return NULL; if (ix == NULL) return NULL;
if (ix->type != PRESERVES_ANNOTATION) return ix; if (ix->type != PRESERVES_ANNOTATION) return ix;
ix++; ix += ix->data._unsigned;
if (ix->type == PRESERVES_ANNOTATION) abort(); if (ix->type == PRESERVES_ANNOTATION) abort();
return ix; return ix;
} }
@ -772,10 +787,11 @@ PRESERVES_OUTOFLINE
/* printf(" %02d: (%5lu) ", i, ip); */ /* printf(" %02d: (%5lu) ", i, ip); */
/* preserves_dump_index_entry(stdout, &r->input, _preserves_reader_index_entry(r, ip), true); */ /* preserves_dump_index_entry(stdout, &r->input, _preserves_reader_index_entry(r, ip), true); */
/* } */ /* } */
/* printf("pos %lu (%05lx), count %lu: ", */ /* printf("pos %lu (%05lx), count %lu, annotation tag seen %d: ", */
/* r->input_pos, */ /* r->input_pos, */
/* r->input_pos, */ /* r->input_pos, */
/* count); */ /* count, */
/* r->annotation_tag_seen); */
int b = _preserves_reader_next(r); int b = _preserves_reader_next(r);
/* printf("tag 0x%02x %s\n", b, preserves_binary_format_tag_name(b)); */ /* printf("tag 0x%02x %s\n", b, preserves_binary_format_tag_name(b)); */
if (b == -1) return _preserves_reader_finish(r, PRESERVES_END_INCOMPLETE_INPUT); if (b == -1) return _preserves_reader_finish(r, PRESERVES_END_INCOMPLETE_INPUT);
@ -847,9 +863,13 @@ PRESERVES_OUTOFLINE
if ((base->type == PRESERVES_RECORD) && (base->len == 0)) { if ((base->type == PRESERVES_RECORD) && (base->len == 0)) {
return _preserves_reader_finish(r, PRESERVES_END_RECORD_MISSING_LABEL); return _preserves_reader_finish(r, PRESERVES_END_RECORD_MISSING_LABEL);
} }
if ((base->type == PRESERVES_ANNOTATION) && (base->len < 2)) { break;
return _preserves_reader_finish(r, PRESERVES_END_ANNOTATION_TOO_SHORT);
case PRESERVES_BINARY_FORMAT_TAG_ANNOTATION:
if (r->annotation_tag_seen || !_preserves_reader_in_annotations(r)) {
RETURN_ON_FAIL(_preserves_reader_push(r, PRESERVES_ANNOTATION));
} }
r->annotation_tag_seen = true;
break; break;
case PRESERVES_BINARY_FORMAT_TAG_EMBEDDED: case PRESERVES_BINARY_FORMAT_TAG_EMBEDDED:
@ -903,10 +923,6 @@ PRESERVES_OUTOFLINE
RETURN_ON_FAIL(_preserves_reader_push(r, PRESERVES_DICTIONARY)); RETURN_ON_FAIL(_preserves_reader_push(r, PRESERVES_DICTIONARY));
break; break;
case PRESERVES_BINARY_FORMAT_TAG_ANNOTATION:
RETURN_ON_FAIL(_preserves_reader_push(r, PRESERVES_ANNOTATION));
break;
default: default:
return _preserves_reader_finish(r, PRESERVES_END_INVALID_TAG); return _preserves_reader_finish(r, PRESERVES_END_INVALID_TAG);
} }
@ -937,6 +953,7 @@ PRESERVES_OUTOFLINE
r->stack_top = 0; r->stack_top = 0;
r->input_pos = 0; r->input_pos = 0;
r->index_pos = 0; r->index_pos = 0;
r->annotation_tag_seen = false;
preserves_bytes_move(&r->input, input); preserves_bytes_move(&r->input, input);
return preserves_read_binary_continue(r, count); return preserves_read_binary_continue(r, count);
@ -1000,10 +1017,13 @@ PRESERVES_IMPLEMENTATION_CHUNK
case PRESERVES_SEQUENCE: case PRESERVES_SEQUENCE:
case PRESERVES_SET: case PRESERVES_SET:
case PRESERVES_DICTIONARY: case PRESERVES_DICTIONARY:
case PRESERVES_ANNOTATION:
fprintf(f, " skip %lu", i->data._unsigned - 1); fprintf(f, " skip %lu", i->data._unsigned - 1);
break; break;
case PRESERVES_ANNOTATION:
fprintf(f, " annotated after %lu", i->data._unsigned - 1);
break;
case PRESERVES_EMBEDDED: case PRESERVES_EMBEDDED:
break; break;

View File

@ -64,4 +64,4 @@ TEST(BinaryReader, ReadSamples) {
auto v = r.next(); auto v = r.next();
ASSERT_TRUE(v); ASSERT_TRUE(v);
// BinaryWriter(cerr) << *v; // BinaryWriter(cerr) << *v;
} }

View File

@ -96,6 +96,19 @@ namespace Preserves {
case BinaryTag::False: return Value<T>::from_bool(false); case BinaryTag::False: return Value<T>::from_bool(false);
case BinaryTag::True: return Value<T>::from_bool(true); case BinaryTag::True: return Value<T>::from_bool(true);
case BinaryTag::End: end_sentinel = true; return boost::none; case BinaryTag::End: end_sentinel = true; return boost::none;
case BinaryTag::Annotation: {
std::vector<Value<T>> annotations;
while (true) {
auto ann = next();
if (!ann) return boost::none;
annotations.push_back(*ann);
if (BinaryTag(i.peek()) != BinaryTag::Annotation) break;
i.get();
}
auto underlying = next();
if (!underlying) return boost::none;
return Value<T>(new AnnotatedValue<T>(std::move(annotations), *underlying));
}
case BinaryTag::Embedded: case BinaryTag::Embedded:
return BinaryReader<>(i).next().map(decodeEmbedded).map(Value<T>::from_embedded); return BinaryReader<>(i).next().map(decodeEmbedded).map(Value<T>::from_embedded);
case BinaryTag::Ieee754: return varint(i).flat_map([&](size_t len)-> boost::optional<Value<T>> { case BinaryTag::Ieee754: return varint(i).flat_map([&](size_t len)-> boost::optional<Value<T>> {
@ -178,20 +191,6 @@ namespace Preserves {
} }
} }
case BinaryTag::Annotation: return next().flat_map([&](auto underlying)-> boost::optional<Value<T>> {
std::vector<Value<T>> annotations;
while (true) {
bool end_rec = false;
auto ann = _next(end_rec);
if (end_rec) {
if (annotations.size() == 0) return boost::none;
return Value<T>(new AnnotatedValue<T>(std::move(annotations), underlying));
}
if (!ann) return boost::none;
annotations.push_back(*ann);
}
});
default: default:
return boost::none; return boost::none;
} }

View File

@ -12,6 +12,7 @@ namespace Preserves {
False = 0x80, False = 0x80,
True = 0x81, True = 0x81,
End = 0x84, End = 0x84,
Annotation = 0x85,
Embedded = 0x86, Embedded = 0x86,
Ieee754 = 0x87, Ieee754 = 0x87,
SignedInteger = 0xb0, SignedInteger = 0xb0,
@ -22,7 +23,6 @@ namespace Preserves {
Sequence = 0xb5, Sequence = 0xb5,
Set = 0xb6, Set = 0xb6,
Dictionary = 0xb7, Dictionary = 0xb7,
Annotation = 0xbf,
}; };
template <uint64_t wholeTest, uint64_t bitTest> template <uint64_t wholeTest, uint64_t bitTest>
@ -238,7 +238,8 @@ namespace Preserves {
template <typename T> template <typename T>
BinaryWriter& annotated(Value<T> const& underlying, std::vector<Value<T>> const& vs) { BinaryWriter& annotated(Value<T> const& underlying, std::vector<Value<T>> const& vs) {
return (*this) << BinaryTag::Annotation << underlying << iterable(vs) << BinaryTag::End; for (auto& v : vs) { (*this) << BinaryTag::Annotation << v; }
return (*this) << underlying;
} }
}; };
} }

View File

@ -72,16 +72,13 @@ export class Annotated<T = GenericEmbedded> implements Preservable<T>, PreserveW
} }
__preserve_on__(encoder: Encoder<T>): void { __preserve_on__(encoder: Encoder<T>): void {
if (encoder.includeAnnotations && this.annotations.length > 0) { if (encoder.includeAnnotations) {
encoder.state.emitbyte(Tag.Annotated);
encoder.push(this.item);
for (const a of this.annotations) { for (const a of this.annotations) {
encoder.state.emitbyte(Tag.Annotation);
encoder.push(a); encoder.push(a);
} }
encoder.state.emitbyte(Tag.End);
} else {
encoder.push(this.item);
} }
encoder.push(this.item);
} }
__preserve_text_on__(w: Writer<T>): void { __preserve_text_on__(w: Writer<T>): void {

View File

@ -2,7 +2,8 @@ export enum Tag {
False = 0x80, False = 0x80,
True, True,
End = 0x84, End = 0x84,
Embedded = 0x86, Annotation,
Embedded,
Ieee754, Ieee754,
SignedInteger = 0xb0, SignedInteger = 0xb0,
@ -13,6 +14,4 @@ export enum Tag {
Sequence, Sequence,
Set, Set,
Dictionary, Dictionary,
Annotated = 0xbf,
} }

View File

@ -142,6 +142,13 @@ export class DecoderState {
wrap<T>(v: Value<T>): Value<T> { wrap<T>(v: Value<T>): Value<T> {
return this.includeAnnotations ? new Annotated(v) : v; return this.includeAnnotations ? new Annotated(v) : v;
} }
unshiftAnnotation<T>(a: Value<T>, v: Annotated<T>): Annotated<T> {
if (this.includeAnnotations) {
v.annotations.unshift(a);
}
return v;
}
} }
export const neverEmbeddedTypeDecode: EmbeddedTypeDecode<never> = { export const neverEmbeddedTypeDecode: EmbeddedTypeDecode<never> = {
@ -199,6 +206,11 @@ export class Decoder<T = never> implements TypedDecoder<T> {
case Tag.False: return this.state.wrap<T>(false); case Tag.False: return this.state.wrap<T>(false);
case Tag.True: return this.state.wrap<T>(true); case Tag.True: return this.state.wrap<T>(true);
case Tag.End: throw new DecodeError("Unexpected Compound end marker"); case Tag.End: throw new DecodeError("Unexpected Compound end marker");
case Tag.Annotation: {
const a = this.next();
const v = this.next() as Annotated<T>;
return this.state.unshiftAnnotation(a, v);
}
case Tag.Embedded: return this.state.wrap<T>(embed(this.embeddedDecode.decode(this.state))); case Tag.Embedded: return this.state.wrap<T>(embed(this.embeddedDecode.decode(this.state)));
case Tag.Ieee754: case Tag.Ieee754:
switch (this.state.varint()) { switch (this.state.varint()) {
@ -218,17 +230,6 @@ export class Decoder<T = never> implements TypedDecoder<T> {
case Tag.Sequence: return this.state.wrap<T>(this.nextvalues()); case Tag.Sequence: return this.state.wrap<T>(this.nextvalues());
case Tag.Set: return this.state.wrap<T>(new Set(this.nextvalues())); case Tag.Set: return this.state.wrap<T>(new Set(this.nextvalues()));
case Tag.Dictionary: return this.state.wrap<T>(Decoder.dictionaryFromArray(this.nextvalues())); case Tag.Dictionary: return this.state.wrap<T>(Decoder.dictionaryFromArray(this.nextvalues()));
case Tag.Annotated: {
const vs = this.nextvalues();
if (vs.length < 2) throw new DecodeError("Too few items in annotated value");
if (this.state.includeAnnotations) {
const a = vs.shift()! as Annotated<T>;
a.annotations.push(... vs);
return a;
} else {
return vs[0];
}
}
default: throw new DecodeError("Unsupported Preserves tag: " + tag); default: throw new DecodeError("Unsupported Preserves tag: " + tag);
} }
} }
@ -263,14 +264,11 @@ export class Decoder<T = never> implements TypedDecoder<T> {
skipAnnotations<R>(f: (reset: () => undefined) => R): R { skipAnnotations<R>(f: (reset: () => undefined) => R): R {
const m = this.mark(); const m = this.mark();
if (!this.state.atEnd() && this.state.packet[this.state.index] === Tag.Annotated) { while (!this.state.atEnd() && this.state.packet[this.state.index] === Tag.Annotation) {
this.state.index++; this.state.index++;
const result = f(() => this.restoreMark(m)); this.skip();
while (!this.state.peekend()) this.skip();
return result;
} else {
return f(() => this.restoreMark(m));
} }
return f(() => this.restoreMark(m));
} }
nextBoolean(): boolean | undefined { nextBoolean(): boolean | undefined {

View File

@ -45,7 +45,7 @@ class Decoder(BinaryCodec):
until a [ShortPacket][preserves.error.ShortPacket] exception is raised: until a [ShortPacket][preserves.error.ShortPacket] exception is raised:
```python ```python
>>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84') >>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84')
>>> d.next() >>> d.next()
123 123
>>> d.next() >>> d.next()
@ -63,7 +63,7 @@ class Decoder(BinaryCodec):
`None`, which is not in the domain of Preserves `Value`s: `None`, which is not in the domain of Preserves `Value`s:
```python ```python
>>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84') >>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84')
>>> d.try_next() >>> d.try_next()
123 123
>>> d.try_next() >>> d.try_next()
@ -79,14 +79,14 @@ class Decoder(BinaryCodec):
over all complete values in an input: over all complete values in an input:
```python ```python
>>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84') >>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84')
>>> list(d) >>> list(d)
[123, 'hello', ()] [123, 'hello', ()]
``` ```
```python ```python
>>> for v in Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84'): >>> for v in Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84'):
... print(repr(v)) ... print(repr(v))
123 123
'hello' 'hello'
@ -97,7 +97,7 @@ class Decoder(BinaryCodec):
Supply `include_annotations=True` to read annotations alongside the annotated values: Supply `include_annotations=True` to read annotations alongside the annotated values:
```python ```python
>>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84', include_annotations=True) >>> d = Decoder(b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84', include_annotations=True)
>>> list(d) >>> list(d)
[123, 'hello', @#x ()] [123, 'hello', @#x ()]
@ -181,6 +181,11 @@ class Decoder(BinaryCodec):
def wrap(self, v): def wrap(self, v):
return Annotated(v) if self.include_annotations else v return Annotated(v) if self.include_annotations else v
def unshift_annotation(self, a, v):
if self.include_annotations:
v.annotations.insert(0, a)
return v
def next(self): def next(self):
"""Reads the next complete `Value` from the internal buffer, raising """Reads the next complete `Value` from the internal buffer, raising
[ShortPacket][preserves.error.ShortPacket] if too few bytes are available, or [ShortPacket][preserves.error.ShortPacket] if too few bytes are available, or
@ -191,6 +196,10 @@ class Decoder(BinaryCodec):
if tag == 0x80: return self.wrap(False) if tag == 0x80: return self.wrap(False)
if tag == 0x81: return self.wrap(True) if tag == 0x81: return self.wrap(True)
if tag == 0x84: raise DecodeError('Unexpected end-of-stream marker') if tag == 0x84: raise DecodeError('Unexpected end-of-stream marker')
if tag == 0x85:
a = self.next()
v = self.next()
return self.unshift_annotation(a, v)
if tag == 0x86: if tag == 0x86:
if self.decode_embedded is None: if self.decode_embedded is None:
raise DecodeError('No decode_embedded function supplied') raise DecodeError('No decode_embedded function supplied')
@ -211,12 +220,6 @@ class Decoder(BinaryCodec):
if tag == 0xb5: return self.wrap(tuple(self.nextvalues())) if tag == 0xb5: return self.wrap(tuple(self.nextvalues()))
if tag == 0xb6: return self.wrap(frozenset(self.nextvalues())) if tag == 0xb6: return self.wrap(frozenset(self.nextvalues()))
if tag == 0xb7: return self.wrap(ImmutableDict.from_kvs(self.nextvalues())) if tag == 0xb7: return self.wrap(ImmutableDict.from_kvs(self.nextvalues()))
if tag == 0xbf:
vs = self.nextvalues()
if len(vs) < 2: raise DecodeError('Too few items in encoded annotated value')
if self.include_annotations:
vs[0].annotations.extend(vs[1:])
return vs[0]
raise DecodeError('Invalid tag: ' + hex(tag)) raise DecodeError('Invalid tag: ' + hex(tag))
def try_next(self): def try_next(self):
@ -263,7 +266,7 @@ class Encoder(BinaryCodec):
>>> e.append('hello') >>> e.append('hello')
>>> e.append(annotate([], Symbol('x'))) >>> e.append(annotate([], Symbol('x')))
>>> e.contents() >>> e.contents()
b'\\xb0\\x01{\\xb1\\x05hello\\xbf\\xb5\\x84\\xb3\\x01x\\x84' b'\\xb0\\x01{\\xb1\\x05hello\\x85\\xb3\\x01x\\xb5\\x84'
``` ```

View File

@ -100,8 +100,8 @@ Evaluating the expression against `testdata` yields the following:
<Test #[tLMHZGlzY2FyZLMIc3VycHJpc2WE] <discard surprise>> <Test #[tLMHZGlzY2FyZLMIc3VycHJpc2WE] <discard surprise>>
<Test #[tLEHYVN0cmluZ7ABA7ABBIQ=] <"aString" 3 4>> <Test #[tLEHYVN0cmluZ7ABA7ABBIQ=] <"aString" 3 4>>
<Test #[tLSzB2Rpc2NhcmSEsAEDsAEEhA==] <<discard> 3 4>> <Test #[tLSzB2Rpc2NhcmSEsAEDsAEEhA==] <<discard> 3 4>>
<Test #[v7SzAVK/swFmswJhZoSEswJhcoQ=] @ar <R @af f>> <Test #[hbMCYXK0swFShbMCYWazAWaE] @ar <R @af f>>
<Test #[tL+zAVKzAmFyhL+zAWazAmFmhIQ=] <@ar R @af f>> <Test #[tIWzAmFyswFShbMCYWazAWaE] <@ar R @af f>>
``` ```

View File

@ -578,14 +578,11 @@ class Annotated(object):
self.item = item self.item = item
def __preserve_write_binary__(self, encoder): def __preserve_write_binary__(self, encoder):
if encoder.include_annotations and self.annotations: if encoder.include_annotations:
encoder.buffer.append(0xbf)
encoder.append(self.item)
for a in self.annotations: for a in self.annotations:
encoder.buffer.append(0x85)
encoder.append(a) encoder.append(a)
encoder.buffer.append(0x84) encoder.append(self.item)
else:
encoder.append(self.item)
def __preserve_write_text__(self, formatter): def __preserve_write_text__(self, formatter):
if formatter.include_annotations: if formatter.include_annotations:

View File

@ -43,17 +43,17 @@
"13/14 and 16/17, depending on how they wish to treat end-of-stream conditions." "13/14 and 16/17, depending on how they wish to treat end-of-stream conditions."
]> ]>
<TestCases { <TestCases {
annotation1: <Test #x"BFB00109B10361626384" @"abc" 9> annotation1: <Test #x"85 B103616263 B00109" @"abc" 9>
annotation2: <Test #x"BF B5 B584 BF B584 B10178 84 84 B103616263 B103646566 84" @"abc" @"def" [[] @"x" []]> annotation2: <Test #x"85 B103616263 85 B103646566 B5 B584 85 B10178 B584 84" @"abc" @"def" [[] @"x" []]>
annotation3: <Test #x"BF B00105 BF B00102 B00101 84 BF B00104 B00103 84 84" @@1 2 @@3 4 5> annotation3: <Test #x"85 85 B00101 B00102 85 85 B00103 B00104 B00105" @@1 2 @@3 4 5>
annotation4: <NondeterministicTest annotation4: <NondeterministicTest
#x"B7 BF B30161 B302616b 84 BF B00101 B3026176 84 BF B30162 B302626b 84 BF B00102 B3026276 84 84" #x"B7 85 B302616b B30161 85 B3026176 B00101 85 B302626b B30162 85 B3026276 B00102 84"
{@ak a: @av 1 @bk b: @bv 2}> {@ak a: @av 1 @bk b: @bv 2}>
annotation5: <Test #x"BF B4 B30152 BF B30166 B3026166 84 84 B3026172 84" @ar <R @af f>> annotation5: <Test #x"85 B3026172 B4 B30152 85 B3026166 B30166 84" @ar <R @af f>>
annotation6: <Test #x"B4 BF B30152 B3026172 84 BF B30166 B3026166 84 84" <@ar R @af f>> annotation6: <Test #x"B4 85 B3026172 B30152 85 B3026166 B30166 84" <@ar R @af f>>
annotation7: annotation7:
;Stop reading symbols at @ -- this test has three separate annotations ;Stop reading symbols at @ -- this test has three separate annotations
<Test #x"BF B584 B30161 B30162 B30163 84" @a@b@c[]> <Test #x"85 B30161 85 B30162 85 B30163 B584" @a@b@c[]>
bytes2: <Test #x"B20568656c6c6f" #"hello"> bytes2: <Test #x"B20568656c6c6f" #"hello">
bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello"> bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello">
bytes3: <Test #x"B203414243" #"ABC"> bytes3: <Test #x"B203414243" #"ABC">

View File

@ -10,7 +10,7 @@
(require "float.rkt" "float-bytes.rkt") (require "float.rkt" "float-bytes.rkt")
(struct record (label fields) #:transparent) (struct record (label fields) #:transparent)
(struct annotated (annotations item) #:transparent) (struct annotated (annotation item) #:transparent)
(struct embedded (value) #:transparent) (struct embedded (value) #:transparent)
;;--------------------------------------------------------------------------- ;;---------------------------------------------------------------------------
@ -24,6 +24,7 @@
[#x80 #f] [#x80 #f]
[#x81 #t] [#x81 #t]
[#x84 '#:end] [#x84 '#:end]
[#x85 (let ((a (next))) (annotated a (next)))]
[#x86 (embedded (next))] [#x86 (embedded (next))]
[#x87 (match (next-byte) [#x87 (match (next-byte)
[4 (bytes->float (next-bytes 4))] [4 (bytes->float (next-bytes 4))]
@ -35,8 +36,7 @@
[#xB4 (apply (lambda (label . fields) (record label fields)) (next-items))] [#xB4 (apply (lambda (label . fields) (record label fields)) (next-items))]
[#xB5 (next-items)] [#xB5 (next-items)]
[#xB6 (list->set (next-items))] [#xB6 (list->set (next-items))]
[#xB7 (apply hash (next-items))] [#xB7 (apply hash (next-items))]))
[#xBF (apply (lambda (underlying . anns) (annotated anns underlying)) (next-items))]))
(define (next-items) (match (next) ['#:end '()] [v (cons v (next-items))])) (define (next-items) (match (next) ['#:end '()] [v (cons v (next-items))]))
@ -77,6 +77,7 @@
[(float _) (write-byte #x87 out-port) (write-byte 4 out-port) (output-bytes (float->bytes v))] [(float _) (write-byte #x87 out-port) (write-byte 4 out-port) (output-bytes (float->bytes v))]
[(? flonum?) (write-byte #x87 out-port) (write-byte 8 out-port) (output-bytes (double->bytes v))] [(? flonum?) (write-byte #x87 out-port) (write-byte 8 out-port) (output-bytes (double->bytes v))]
[(annotated a v) (write-byte #x85 out-port) (output a) (output v)]
[(embedded v) (write-byte #x86 out-port) (output v)] [(embedded v) (write-byte #x86 out-port) (output v)]
[(? integer?) [(? integer?)
@ -96,7 +97,6 @@
[(? list?) (with-seq 5 (for-each output v))] [(? list?) (with-seq 5 (for-each output v))]
[(? set?) (with-seq 6 (output-set v))] [(? set?) (with-seq 6 (output-set v))]
[(? hash?) (with-seq 7 (output-hash v))] [(? hash?) (with-seq 7 (output-hash v))]
[(annotated as v) (with-seq 15 (output v) (for-each output as))]
[_ (error 'write-preserve/binary "Invalid value: ~v" v)])) [_ (error 'write-preserve/binary "Invalid value: ~v" v)]))

View File

@ -70,6 +70,10 @@
[#x80 #f] [#x80 #f]
[#x81 #t] [#x81 #t]
[#x84 '#:end] [#x84 '#:end]
[#x85 (let ((a (next)))
(if read-annotations?
(annotate (next) a)
(next)))]
[#x86 (embedded (decode-embedded (next)))] [#x86 (embedded (decode-embedded (next)))]
[#x87 (match (next-varint) [#x87 (match (next-varint)
[4 (bytes->float (next-bytes 4))] [4 (bytes->float (next-bytes 4))]
@ -83,7 +87,6 @@
[#xB5 (next-items)] [#xB5 (next-items)]
[#xB6 (list->set (next-items))] [#xB6 (list->set (next-items))]
[#xB7 (build-dictionary (next-items))] [#xB7 (build-dictionary (next-items))]
[#xBF (apply annotate (next-items))]
[_ (return (on-fail "Invalid Preserves binary tag: ~v" lead-byte))])) [_ (return (on-fail "Invalid Preserves binary tag: ~v" lead-byte))]))
(define (eof-guard v) (define (eof-guard v)

View File

@ -43,17 +43,17 @@
"13/14 and 16/17, depending on how they wish to treat end-of-stream conditions." "13/14 and 16/17, depending on how they wish to treat end-of-stream conditions."
]> ]>
<TestCases { <TestCases {
annotation1: <Test #x"BFB00109B10361626384" @"abc" 9> annotation1: <Test #x"85 B103616263 B00109" @"abc" 9>
annotation2: <Test #x"BF B5 B584 BF B584 B10178 84 84 B103616263 B103646566 84" @"abc" @"def" [[] @"x" []]> annotation2: <Test #x"85 B103616263 85 B103646566 B5 B584 85 B10178 B584 84" @"abc" @"def" [[] @"x" []]>
annotation3: <Test #x"BF B00105 BF B00102 B00101 84 BF B00104 B00103 84 84" @@1 2 @@3 4 5> annotation3: <Test #x"85 85 B00101 B00102 85 85 B00103 B00104 B00105" @@1 2 @@3 4 5>
annotation4: <NondeterministicTest annotation4: <NondeterministicTest
#x"B7 BF B30161 B302616b 84 BF B00101 B3026176 84 BF B30162 B302626b 84 BF B00102 B3026276 84 84" #x"B7 85 B302616b B30161 85 B3026176 B00101 85 B302626b B30162 85 B3026276 B00102 84"
{@ak a: @av 1 @bk b: @bv 2}> {@ak a: @av 1 @bk b: @bv 2}>
annotation5: <Test #x"BF B4 B30152 BF B30166 B3026166 84 84 B3026172 84" @ar <R @af f>> annotation5: <Test #x"85 B3026172 B4 B30152 85 B3026166 B30166 84" @ar <R @af f>>
annotation6: <Test #x"B4 BF B30152 B3026172 84 BF B30166 B3026166 84 84" <@ar R @af f>> annotation6: <Test #x"B4 85 B3026172 B30152 85 B3026166 B30166 84" <@ar R @af f>>
annotation7: annotation7:
;Stop reading symbols at @ -- this test has three separate annotations ;Stop reading symbols at @ -- this test has three separate annotations
<Test #x"BF B584 B30161 B30162 B30163 84" @a@b@c[]> <Test #x"85 B30161 85 B30162 85 B30163 B584" @a@b@c[]>
bytes2: <Test #x"B20568656c6c6f" #"hello"> bytes2: <Test #x"B20568656c6c6f" #"hello">
bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello"> bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello">
bytes3: <Test #x"B203414243" #"ABC"> bytes3: <Test #x"B203414243" #"ABC">

View File

@ -115,9 +115,11 @@
[(? dict?) (with-seq 7 (output-dict v))] [(? dict?) (with-seq 7 (output-dict v))]
[(annotated as _ v) [(annotated as _ v)
(if (and write-annotations? (pair? as)) (when write-annotations?
(with-seq 15 (output v) (output-all as)) (for [(a (in-list as))]
(output v))] (output-byte #x85)
(output a)))
(output v)]
[(embedded value) [(embedded value)
(output-byte #x86) (output-byte #x86)

View File

@ -42,7 +42,7 @@ impl<N: preserves::value::NestedValue> Default for Language<N> {
fn default() -> Self { fn default() -> Self {
Language { Language {
LIT_15_FALSE: /* #f */ _support::decode_lit(&[128]).unwrap(), LIT_15_FALSE: /* #f */ _support::decode_lit(&[128]).unwrap(),
LIT_28_1: /* 1 */ _support::decode_lit(&[145]).unwrap(), LIT_28_1: /* 1 */ _support::decode_lit(&[176, 1, 1]).unwrap(),
LIT_0_BOOLEAN: /* Boolean */ _support::decode_lit(&[179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap(), LIT_0_BOOLEAN: /* Boolean */ _support::decode_lit(&[179, 7, 66, 111, 111, 108, 101, 97, 110]).unwrap(),
LIT_5_BYTE_STRING: /* ByteString */ _support::decode_lit(&[179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap(), LIT_5_BYTE_STRING: /* ByteString */ _support::decode_lit(&[179, 10, 66, 121, 116, 101, 83, 116, 114, 105, 110, 103]).unwrap(),
LIT_2_DOUBLE: /* Double */ _support::decode_lit(&[179, 6, 68, 111, 117, 98, 108, 101]).unwrap(), LIT_2_DOUBLE: /* Double */ _support::decode_lit(&[179, 6, 68, 111, 117, 98, 108, 101]).unwrap(),
@ -78,187 +78,188 @@ pub fn _bundle() -> &'static [u8] {
b"\ b"\
\xb4\xb3\x06\x62\x75\x6e\x64\x6c\x65\xb7\xb5\xb3\x06\x73\x63\x68\ \xb4\xb3\x06\x62\x75\x6e\x64\x6c\x65\xb7\xb5\xb3\x06\x73\x63\x68\
\x65\x6d\x61\x84\xb4\xb3\x06\x73\x63\x68\x65\x6d\x61\xb7\xb3\x07\ \x65\x6d\x61\x84\xb4\xb3\x06\x73\x63\x68\x65\x6d\x61\xb7\xb3\x07\
\x76\x65\x72\x73\x69\x6f\x6e\x91\xb3\x0b\x64\x65\x66\x69\x6e\x69\ \x76\x65\x72\x73\x69\x6f\x6e\xb0\x01\x01\xb3\x0b\x64\x65\x66\x69\
\x74\x69\x6f\x6e\x73\xb7\xb3\x03\x52\x65\x66\xb4\xb3\x03\x72\x65\ \x6e\x69\x74\x69\x6f\x6e\x73\xb7\xb3\x03\x52\x65\x66\xb4\xb3\x03\
\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x72\x65\x66\x84\xb4\xb3\x05\ \x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x72\x65\x66\x84\xb4\
\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x06\ \xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\
\x6d\x6f\x64\x75\x6c\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0a\ \xb3\x06\x6d\x6f\x64\x75\x6c\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\
\x4d\x6f\x64\x75\x6c\x65\x50\x61\x74\x68\x84\x84\xb4\xb3\x05\x6e\ \xb3\x0a\x4d\x6f\x64\x75\x6c\x65\x50\x61\x74\x68\x84\x84\xb4\xb3\
\x61\x6d\x65\x64\xb3\x04\x6e\x61\x6d\x65\xb4\xb3\x04\x61\x74\x6f\ \x05\x6e\x61\x6d\x65\x64\xb3\x04\x6e\x61\x6d\x65\xb4\xb3\x04\x61\
\x6d\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\x84\x84\x84\xb3\x06\ \x74\x6f\x6d\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\x84\x84\x84\
\x42\x75\x6e\x64\x6c\x65\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\ \xb3\x06\x42\x75\x6e\x64\x6c\x65\xb4\xb3\x03\x72\x65\x63\xb4\xb3\
\x69\x74\xb3\x06\x62\x75\x6e\x64\x6c\x65\x84\xb4\xb3\x05\x74\x75\ \x03\x6c\x69\x74\xb3\x06\x62\x75\x6e\x64\x6c\x65\x84\xb4\xb3\x05\
\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\x6d\x6f\
\x64\x75\x6c\x65\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x4d\
\x6f\x64\x75\x6c\x65\x73\x84\x84\x84\x84\x84\xb3\x06\x53\x63\x68\
\x65\x6d\x61\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\
\x06\x73\x63\x68\x65\x6d\x61\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\
\xb5\xb4\xb3\x04\x64\x69\x63\x74\xb7\xb3\x07\x76\x65\x72\x73\x69\
\x6f\x6e\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\x76\x65\x72\x73\
\x69\x6f\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x56\x65\x72\
\x73\x69\x6f\x6e\x84\x84\xb3\x0b\x64\x65\x66\x69\x6e\x69\x74\x69\
\x6f\x6e\x73\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x0b\x64\x65\x66\
\x69\x6e\x69\x74\x69\x6f\x6e\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\
\xb3\x0b\x44\x65\x66\x69\x6e\x69\x74\x69\x6f\x6e\x73\x84\x84\xb3\
\x0c\x65\x6d\x62\x65\x64\x64\x65\x64\x54\x79\x70\x65\xb4\xb3\x05\
\x6e\x61\x6d\x65\x64\xb3\x0c\x65\x6d\x62\x65\x64\x64\x65\x64\x54\
\x79\x70\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x45\x6d\x62\
\x65\x64\x64\x65\x64\x54\x79\x70\x65\x4e\x61\x6d\x65\x84\x84\x84\
\x84\x84\x84\x84\xb3\x07\x42\x69\x6e\x64\x69\x6e\x67\xb4\xb3\x03\
\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x05\x6e\x61\x6d\x65\x64\
\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\
\x65\x64\xb3\x04\x6e\x61\x6d\x65\xb4\xb3\x04\x61\x74\x6f\x6d\xb3\
\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\
\x64\xb3\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\
\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\
\x6e\x84\x84\x84\x84\x84\xb3\x07\x4d\x6f\x64\x75\x6c\x65\x73\xb4\
\xb3\x06\x64\x69\x63\x74\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\
\xb3\x0a\x4d\x6f\x64\x75\x6c\x65\x50\x61\x74\x68\x84\xb4\xb3\x03\
\x72\x65\x66\xb5\x84\xb3\x06\x53\x63\x68\x65\x6d\x61\x84\x84\xb3\
\x07\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\
\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\
\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\
\x74\x74\x65\x72\x6e\x84\x84\xb5\xb1\x0f\x43\x6f\x6d\x70\x6f\x75\
\x6e\x64\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\xb5\
\x84\xb3\x0f\x43\x6f\x6d\x70\x6f\x75\x6e\x64\x50\x61\x74\x74\x65\
\x72\x6e\x84\x84\x84\x84\xb3\x07\x56\x65\x72\x73\x69\x6f\x6e\xb4\
\xb3\x03\x6c\x69\x74\x91\x84\xb3\x08\x41\x74\x6f\x6d\x4b\x69\x6e\
\x64\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x07\x42\x6f\x6f\x6c\x65\x61\
\x6e\xb4\xb3\x03\x6c\x69\x74\xb3\x07\x42\x6f\x6f\x6c\x65\x61\x6e\
\x84\x84\xb5\xb1\x05\x46\x6c\x6f\x61\x74\xb4\xb3\x03\x6c\x69\x74\
\xb3\x05\x46\x6c\x6f\x61\x74\x84\x84\xb5\xb1\x06\x44\x6f\x75\x62\
\x6c\x65\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x44\x6f\x75\x62\x6c\x65\
\x84\x84\xb5\xb1\x0d\x53\x69\x67\x6e\x65\x64\x49\x6e\x74\x65\x67\
\x65\x72\xb4\xb3\x03\x6c\x69\x74\xb3\x0d\x53\x69\x67\x6e\x65\x64\
\x49\x6e\x74\x65\x67\x65\x72\x84\x84\xb5\xb1\x06\x53\x74\x72\x69\
\x6e\x67\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x53\x74\x72\x69\x6e\x67\
\x84\x84\xb5\xb1\x0a\x42\x79\x74\x65\x53\x74\x72\x69\x6e\x67\xb4\
\xb3\x03\x6c\x69\x74\xb3\x0a\x42\x79\x74\x65\x53\x74\x72\x69\x6e\
\x67\x84\x84\xb5\xb1\x06\x53\x79\x6d\x62\x6f\x6c\xb4\xb3\x03\x6c\
\x69\x74\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\x84\x84\xb3\x0a\
\x44\x65\x66\x69\x6e\x69\x74\x69\x6f\x6e\xb4\xb3\x02\x6f\x72\xb5\
\xb5\xb1\x02\x6f\x72\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\
\x74\xb3\x02\x6f\x72\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\
\xb3\x0b\x74\x75\x70\x6c\x65\x50\x72\x65\x66\x69\x78\xb5\xb4\xb3\
\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x30\
\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x4e\x61\x6d\x65\x64\x41\
\x6c\x74\x65\x72\x6e\x61\x74\x69\x76\x65\x84\x84\xb4\xb3\x05\x6e\
\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x31\xb4\xb3\
\x03\x72\x65\x66\xb5\x84\xb3\x10\x4e\x61\x6d\x65\x64\x41\x6c\x74\
\x65\x72\x6e\x61\x74\x69\x76\x65\x84\x84\x84\xb4\xb3\x05\x6e\x61\
\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x4e\xb4\xb3\x05\
\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x4e\
\x61\x6d\x65\x64\x41\x6c\x74\x65\x72\x6e\x61\x74\x69\x76\x65\x84\
\x84\x84\x84\x84\x84\x84\x84\xb5\xb1\x03\x61\x6e\x64\xb4\xb3\x03\
\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x61\x6e\x64\x84\xb4\
\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x0b\x74\x75\x70\x6c\x65\
\x50\x72\x65\x66\x69\x78\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\
\x08\x70\x61\x74\x74\x65\x72\x6e\x30\xb4\xb3\x03\x72\x65\x66\xb5\
\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\
\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\
\x72\x6e\x31\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\
\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\xb4\xb3\x05\x6e\
\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x4e\xb4\xb3\
\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\
\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\
\x84\x84\x84\x84\xb5\xb1\x07\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\
\x03\x72\x65\x66\xb5\x84\xb3\x07\x50\x61\x74\x74\x65\x72\x6e\x84\
\x84\x84\x84\xb3\x0a\x4d\x6f\x64\x75\x6c\x65\x50\x61\x74\x68\xb4\
\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\x04\x61\x74\x6f\x6d\xb3\x06\
\x53\x79\x6d\x62\x6f\x6c\x84\x84\xb3\x0b\x44\x65\x66\x69\x6e\x69\
\x74\x69\x6f\x6e\x73\xb4\xb3\x06\x64\x69\x63\x74\x6f\x66\xb4\xb3\
\x04\x61\x74\x6f\x6d\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\xb4\xb3\
\x03\x72\x65\x66\xb5\x84\xb3\x0a\x44\x65\x66\x69\x6e\x69\x74\x69\
\x6f\x6e\x84\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\
\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x05\x6e\x61\x6d\x65\x64\
\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x42\x69\x6e\x64\x69\x6e\
\x67\x84\x84\xb5\xb1\x09\x61\x6e\x6f\x6e\x79\x6d\x6f\x75\x73\xb4\
\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x50\x61\x74\x74\x65\x72\x6e\
\x84\x84\x84\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\
\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x03\x61\x6e\x79\xb4\
\xb3\x03\x6c\x69\x74\xb3\x03\x61\x6e\x79\x84\x84\xb5\xb1\x04\x61\
\x74\x6f\x6d\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\
\x04\x61\x74\x6f\x6d\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\
\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x61\x74\x6f\x6d\x4b\x69\x6e\
\x64\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x08\x41\x74\x6f\x6d\x4b\
\x69\x6e\x64\x84\x84\x84\x84\x84\x84\xb5\xb1\x08\x65\x6d\x62\x65\
\x64\x64\x65\x64\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\
\xb3\x08\x65\x6d\x62\x65\x64\x64\x65\x64\x84\xb4\xb3\x05\x74\x75\
\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x09\x69\x6e\
\x74\x65\x72\x66\x61\x63\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\
\x84\x84\x84\x84\xb5\xb1\x03\x6c\x69\x74\xb4\xb3\x03\x72\x65\x63\
\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x6c\x69\x74\x84\xb4\xb3\x05\x74\
\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x05\x76\
\x61\x6c\x75\x65\xb3\x03\x61\x6e\x79\x84\x84\x84\x84\x84\xb5\xb1\
\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\
\x69\x74\xb3\x05\x73\x65\x71\x6f\x66\x84\xb4\xb3\x05\x74\x75\x70\
\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\x70\x61\x74\
\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\
\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\
\x84\xb5\xb1\x05\x73\x65\x74\x6f\x66\xb4\xb3\x03\x72\x65\x63\xb4\
\xb3\x03\x6c\x69\x74\xb3\x05\x73\x65\x74\x6f\x66\x84\xb4\xb3\x05\
\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\ \x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\
\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\ \x6d\x6f\x64\x75\x6c\x65\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\ \x07\x4d\x6f\x64\x75\x6c\x65\x73\x84\x84\x84\x84\x84\xb3\x06\x53\
\x84\x84\x84\x84\xb5\xb1\x06\x64\x69\x63\x74\x6f\x66\xb4\xb3\x03\ \x63\x68\x65\x6d\x61\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\
\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x64\x69\x63\x74\x6f\ \x74\xb3\x06\x73\x63\x68\x65\x6d\x61\x84\xb4\xb3\x05\x74\x75\x70\
\x66\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\ \x6c\x65\xb5\xb4\xb3\x04\x64\x69\x63\x74\xb7\xb3\x07\x76\x65\x72\
\x6d\x65\x64\xb3\x03\x6b\x65\x79\xb4\xb3\x03\x72\x65\x66\xb5\x84\ \x73\x69\x6f\x6e\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\x76\x65\
\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\ \x72\x73\x69\x6f\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x56\
\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x05\x76\x61\x6c\x75\x65\ \x65\x72\x73\x69\x6f\x6e\x84\x84\xb3\x0b\x64\x65\x66\x69\x6e\x69\
\x74\x69\x6f\x6e\x73\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x0b\x64\
\x65\x66\x69\x6e\x69\x74\x69\x6f\x6e\x73\xb4\xb3\x03\x72\x65\x66\
\xb5\x84\xb3\x0b\x44\x65\x66\x69\x6e\x69\x74\x69\x6f\x6e\x73\x84\
\x84\xb3\x0c\x65\x6d\x62\x65\x64\x64\x65\x64\x54\x79\x70\x65\xb4\
\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x0c\x65\x6d\x62\x65\x64\x64\x65\
\x64\x54\x79\x70\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x45\
\x6d\x62\x65\x64\x64\x65\x64\x54\x79\x70\x65\x4e\x61\x6d\x65\x84\
\x84\x84\x84\x84\x84\x84\xb3\x07\x42\x69\x6e\x64\x69\x6e\x67\xb4\
\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x05\x6e\x61\x6d\
\x65\x64\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\
\x61\x6d\x65\x64\xb3\x04\x6e\x61\x6d\x65\xb4\xb3\x04\x61\x74\x6f\
\x6d\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\xb4\xb3\x05\x6e\x61\
\x6d\x65\x64\xb3\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\
\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\
\x65\x72\x6e\x84\x84\x84\x84\x84\xb3\x07\x4d\x6f\x64\x75\x6c\x65\
\x73\xb4\xb3\x06\x64\x69\x63\x74\x6f\x66\xb4\xb3\x03\x72\x65\x66\
\xb5\x84\xb3\x0a\x4d\x6f\x64\x75\x6c\x65\x50\x61\x74\x68\x84\xb4\
\xb3\x03\x72\x65\x66\xb5\x84\xb3\x06\x53\x63\x68\x65\x6d\x61\x84\
\x84\xb3\x07\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\
\xb5\xb1\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\
\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\ \xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\
\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\x84\xb5\xb1\x03\ \x50\x61\x74\x74\x65\x72\x6e\x84\x84\xb5\xb1\x0f\x43\x6f\x6d\x70\
\x52\x65\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x03\x52\x65\x66\ \x6f\x75\x6e\x64\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\
\x84\x84\x84\x84\xb3\x0f\x43\x6f\x6d\x70\x6f\x75\x6e\x64\x50\x61\ \x66\xb5\x84\xb3\x0f\x43\x6f\x6d\x70\x6f\x75\x6e\x64\x50\x61\x74\
\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x03\x72\x65\ \x74\x65\x72\x6e\x84\x84\x84\x84\xb3\x07\x56\x65\x72\x73\x69\x6f\
\x63\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x72\ \x6e\xb4\xb3\x03\x6c\x69\x74\xb0\x01\x01\x84\xb3\x08\x41\x74\x6f\
\x65\x63\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\ \x6d\x4b\x69\x6e\x64\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x07\x42\x6f\
\x61\x6d\x65\x64\xb3\x05\x6c\x61\x62\x65\x6c\xb4\xb3\x03\x72\x65\ \x6f\x6c\x65\x61\x6e\xb4\xb3\x03\x6c\x69\x74\xb3\x07\x42\x6f\x6f\
\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\ \x6c\x65\x61\x6e\x84\x84\xb5\xb1\x05\x46\x6c\x6f\x61\x74\xb4\xb3\
\x6e\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x06\x66\x69\x65\ \x03\x6c\x69\x74\xb3\x05\x46\x6c\x6f\x61\x74\x84\x84\xb5\xb1\x06\
\x6c\x64\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\ \x44\x6f\x75\x62\x6c\x65\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x44\x6f\
\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\x84\xb5\ \x75\x62\x6c\x65\x84\x84\xb5\xb1\x0d\x53\x69\x67\x6e\x65\x64\x49\
\xb1\x05\x74\x75\x70\x6c\x65\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\ \x6e\x74\x65\x67\x65\x72\xb4\xb3\x03\x6c\x69\x74\xb3\x0d\x53\x69\
\x6c\x69\x74\xb3\x05\x74\x75\x70\x6c\x65\x84\xb4\xb3\x05\x74\x75\ \x67\x6e\x65\x64\x49\x6e\x74\x65\x67\x65\x72\x84\x84\xb5\xb1\x06\
\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\ \x53\x74\x72\x69\x6e\x67\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x53\x74\
\x74\x74\x65\x72\x6e\x73\xb4\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\ \x72\x69\x6e\x67\x84\x84\xb5\xb1\x0a\x42\x79\x74\x65\x53\x74\x72\
\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\ \x69\x6e\x67\xb4\xb3\x03\x6c\x69\x74\xb3\x0a\x42\x79\x74\x65\x53\
\x74\x65\x72\x6e\x84\x84\x84\x84\x84\x84\x84\xb5\xb1\x0b\x74\x75\ \x74\x72\x69\x6e\x67\x84\x84\xb5\xb1\x06\x53\x79\x6d\x62\x6f\x6c\
\x70\x6c\x65\x50\x72\x65\x66\x69\x78\xb4\xb3\x03\x72\x65\x63\xb4\ \xb4\xb3\x03\x6c\x69\x74\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\
\xb3\x03\x6c\x69\x74\xb3\x0b\x74\x75\x70\x6c\x65\x50\x72\x65\x66\ \x84\x84\xb3\x0a\x44\x65\x66\x69\x6e\x69\x74\x69\x6f\x6e\xb4\xb3\
\x69\x78\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\ \x02\x6f\x72\xb5\xb5\xb1\x02\x6f\x72\xb4\xb3\x03\x72\x65\x63\xb4\
\x61\x6d\x65\x64\xb3\x05\x66\x69\x78\x65\x64\xb4\xb3\x05\x73\x65\ \xb3\x03\x6c\x69\x74\xb3\x02\x6f\x72\x84\xb4\xb3\x05\x74\x75\x70\
\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\ \x6c\x65\xb5\xb4\xb3\x0b\x74\x75\x70\x6c\x65\x50\x72\x65\x66\x69\
\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\xb4\xb3\x05\x6e\ \x78\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\
\x61\x6d\x65\x64\xb3\x08\x76\x61\x72\x69\x61\x62\x6c\x65\xb4\xb3\ \x65\x72\x6e\x30\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x4e\x61\
\x03\x72\x65\x66\xb5\x84\xb3\x12\x4e\x61\x6d\x65\x64\x53\x69\x6d\ \x6d\x65\x64\x41\x6c\x74\x65\x72\x6e\x61\x74\x69\x76\x65\x84\x84\
\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\x84\ \xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\
\xb5\xb1\x04\x64\x69\x63\x74\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\ \x6e\x31\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x10\x4e\x61\x6d\x65\
\x6c\x69\x74\xb3\x04\x64\x69\x63\x74\x84\xb4\xb3\x05\x74\x75\x70\ \x64\x41\x6c\x74\x65\x72\x6e\x61\x74\x69\x76\x65\x84\x84\x84\xb4\
\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x07\x65\x6e\x74\ \xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\
\x72\x69\x65\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x11\x44\x69\ \x4e\xb4\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\
\x63\x74\x69\x6f\x6e\x61\x72\x79\x45\x6e\x74\x72\x69\x65\x73\x84\ \x84\xb3\x10\x4e\x61\x6d\x65\x64\x41\x6c\x74\x65\x72\x6e\x61\x74\
\x84\x84\x84\x84\x84\x84\x84\xb3\x10\x45\x6d\x62\x65\x64\x64\x65\ \x69\x76\x65\x84\x84\x84\x84\x84\x84\x84\x84\xb5\xb1\x03\x61\x6e\
\x64\x54\x79\x70\x65\x4e\x61\x6d\x65\xb4\xb3\x02\x6f\x72\xb5\xb5\ \x64\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x61\
\xb1\x05\x66\x61\x6c\x73\x65\xb4\xb3\x03\x6c\x69\x74\x80\x84\x84\ \x6e\x64\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x0b\x74\
\xb5\xb1\x03\x52\x65\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x03\ \x75\x70\x6c\x65\x50\x72\x65\x66\x69\x78\xb5\xb4\xb3\x05\x6e\x61\
\x52\x65\x66\x84\x84\x84\x84\xb3\x10\x4e\x61\x6d\x65\x64\x41\x6c\ \x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x30\xb4\xb3\x03\
\x74\x65\x72\x6e\x61\x74\x69\x76\x65\xb4\xb3\x05\x74\x75\x70\x6c\ \x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\
\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x0c\x76\x61\x72\x69\ \x65\x72\x6e\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\
\x61\x6e\x74\x4c\x61\x62\x65\x6c\xb4\xb3\x04\x61\x74\x6f\x6d\xb3\ \x61\x74\x74\x65\x72\x6e\x31\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x06\x53\x74\x72\x69\x6e\x67\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\ \x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\
\x64\xb3\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\ \xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x70\x61\x74\x74\x65\x72\
\xb5\x84\xb3\x07\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\xb3\ \x6e\x4e\xb4\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\
\x11\x44\x69\x63\x74\x69\x6f\x6e\x61\x72\x79\x45\x6e\x74\x72\x69\ \xb5\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\
\x65\x73\xb4\xb3\x06\x64\x69\x63\x74\x6f\x66\xb3\x03\x61\x6e\x79\ \x84\x84\x84\x84\x84\x84\x84\x84\xb5\xb1\x07\x50\x61\x74\x74\x65\
\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x12\x4e\x61\x6d\x65\x64\x53\ \x72\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x50\x61\x74\x74\
\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\xb3\x12\ \x65\x72\x6e\x84\x84\x84\x84\xb3\x0a\x4d\x6f\x64\x75\x6c\x65\x50\
\x4e\x61\x6d\x65\x64\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\ \x61\x74\x68\xb4\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\x04\x61\x74\
\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x05\x6e\x61\x6d\x65\x64\ \x6f\x6d\xb3\x06\x53\x79\x6d\x62\x6f\x6c\x84\x84\xb3\x0b\x44\x65\
\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x42\x69\x6e\x64\x69\x6e\ \x66\x69\x6e\x69\x74\x69\x6f\x6e\x73\xb4\xb3\x06\x64\x69\x63\x74\
\x67\x84\x84\xb5\xb1\x09\x61\x6e\x6f\x6e\x79\x6d\x6f\x75\x73\xb4\ \x6f\x66\xb4\xb3\x04\x61\x74\x6f\x6d\xb3\x06\x53\x79\x6d\x62\x6f\
\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\ \x6c\x84\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0a\x44\x65\x66\x69\
\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\xb3\x0c\x65\x6d\x62\ \x6e\x69\x74\x69\x6f\x6e\x84\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\
\x65\x64\x64\x65\x64\x54\x79\x70\x65\x80\x84\x84\x84\x84" \x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x05\x6e\
\x61\x6d\x65\x64\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x42\x69\
\x6e\x64\x69\x6e\x67\x84\x84\xb5\xb1\x09\x61\x6e\x6f\x6e\x79\x6d\
\x6f\x75\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x50\x61\x74\
\x74\x65\x72\x6e\x84\x84\x84\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\
\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x03\
\x61\x6e\x79\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x61\x6e\x79\x84\x84\
\xb5\xb1\x04\x61\x74\x6f\x6d\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\
\x6c\x69\x74\xb3\x04\x61\x74\x6f\x6d\x84\xb4\xb3\x05\x74\x75\x70\
\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x61\x74\x6f\
\x6d\x4b\x69\x6e\x64\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x08\x41\
\x74\x6f\x6d\x4b\x69\x6e\x64\x84\x84\x84\x84\x84\x84\xb5\xb1\x08\
\x65\x6d\x62\x65\x64\x64\x65\x64\xb4\xb3\x03\x72\x65\x63\xb4\xb3\
\x03\x6c\x69\x74\xb3\x08\x65\x6d\x62\x65\x64\x64\x65\x64\x84\xb4\
\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\
\xb3\x09\x69\x6e\x74\x65\x72\x66\x61\x63\x65\xb4\xb3\x03\x72\x65\
\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\
\x72\x6e\x84\x84\x84\x84\x84\x84\xb5\xb1\x03\x6c\x69\x74\xb4\xb3\
\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x03\x6c\x69\x74\x84\
\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\
\x64\xb3\x05\x76\x61\x6c\x75\x65\xb3\x03\x61\x6e\x79\x84\x84\x84\
\x84\x84\xb5\xb1\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x63\
\xb4\xb3\x03\x6c\x69\x74\xb3\x05\x73\x65\x71\x6f\x66\x84\xb4\xb3\
\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\
\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\x66\xb5\x84\
\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\
\x84\x84\x84\x84\x84\xb5\xb1\x05\x73\x65\x74\x6f\x66\xb4\xb3\x03\
\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x05\x73\x65\x74\x6f\x66\
\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\
\x65\x64\xb3\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\x03\x72\x65\
\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\
\x72\x6e\x84\x84\x84\x84\x84\x84\xb5\xb1\x06\x64\x69\x63\x74\x6f\
\x66\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x06\x64\
\x69\x63\x74\x6f\x66\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\
\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x03\x6b\x65\x79\xb4\xb3\x03\x72\
\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\
\x65\x72\x6e\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x05\x76\
\x61\x6c\x75\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\
\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\
\x84\xb5\xb1\x03\x52\x65\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x03\x52\x65\x66\x84\x84\x84\x84\xb3\x0f\x43\x6f\x6d\x70\x6f\x75\
\x6e\x64\x50\x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\
\xb1\x03\x72\x65\x63\xb4\xb3\x03\x72\x65\x63\xb4\xb3\x03\x6c\x69\
\x74\xb3\x03\x72\x65\x63\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\
\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x05\x6c\x61\x62\x65\x6c\xb4\
\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\x65\x64\x50\x61\
\x74\x74\x65\x72\x6e\x84\x84\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\
\x06\x66\x69\x65\x6c\x64\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\
\x84\x84\x84\xb5\xb1\x05\x74\x75\x70\x6c\x65\xb4\xb3\x03\x72\x65\
\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x05\x74\x75\x70\x6c\x65\x84\xb4\
\xb3\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\
\xb3\x08\x70\x61\x74\x74\x65\x72\x6e\x73\xb4\xb3\x05\x73\x65\x71\
\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0c\x4e\x61\x6d\x65\
\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\x84\x84\xb5\
\xb1\x0b\x74\x75\x70\x6c\x65\x50\x72\x65\x66\x69\x78\xb4\xb3\x03\
\x72\x65\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x0b\x74\x75\x70\x6c\x65\
\x50\x72\x65\x66\x69\x78\x84\xb4\xb3\x05\x74\x75\x70\x6c\x65\xb5\
\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x05\x66\x69\x78\x65\x64\xb4\
\xb3\x05\x73\x65\x71\x6f\x66\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\
\x0c\x4e\x61\x6d\x65\x64\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\
\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x08\x76\x61\x72\x69\x61\x62\
\x6c\x65\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x12\x4e\x61\x6d\x65\
\x64\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\
\x84\x84\x84\x84\xb5\xb1\x04\x64\x69\x63\x74\xb4\xb3\x03\x72\x65\
\x63\xb4\xb3\x03\x6c\x69\x74\xb3\x04\x64\x69\x63\x74\x84\xb4\xb3\
\x05\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\
\x07\x65\x6e\x74\x72\x69\x65\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\
\xb3\x11\x44\x69\x63\x74\x69\x6f\x6e\x61\x72\x79\x45\x6e\x74\x72\
\x69\x65\x73\x84\x84\x84\x84\x84\x84\x84\x84\xb3\x10\x45\x6d\x62\
\x65\x64\x64\x65\x64\x54\x79\x70\x65\x4e\x61\x6d\x65\xb4\xb3\x02\
\x6f\x72\xb5\xb5\xb1\x05\x66\x61\x6c\x73\x65\xb4\xb3\x03\x6c\x69\
\x74\x80\x84\x84\xb5\xb1\x03\x52\x65\x66\xb4\xb3\x03\x72\x65\x66\
\xb5\x84\xb3\x03\x52\x65\x66\x84\x84\x84\x84\xb3\x10\x4e\x61\x6d\
\x65\x64\x41\x6c\x74\x65\x72\x6e\x61\x74\x69\x76\x65\xb4\xb3\x05\
\x74\x75\x70\x6c\x65\xb5\xb4\xb3\x05\x6e\x61\x6d\x65\x64\xb3\x0c\
\x76\x61\x72\x69\x61\x6e\x74\x4c\x61\x62\x65\x6c\xb4\xb3\x04\x61\
\x74\x6f\x6d\xb3\x06\x53\x74\x72\x69\x6e\x67\x84\x84\xb4\xb3\x05\
\x6e\x61\x6d\x65\x64\xb3\x07\x70\x61\x74\x74\x65\x72\x6e\xb4\xb3\
\x03\x72\x65\x66\xb5\x84\xb3\x07\x50\x61\x74\x74\x65\x72\x6e\x84\
\x84\x84\x84\xb3\x11\x44\x69\x63\x74\x69\x6f\x6e\x61\x72\x79\x45\
\x6e\x74\x72\x69\x65\x73\xb4\xb3\x06\x64\x69\x63\x74\x6f\x66\xb3\
\x03\x61\x6e\x79\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x12\x4e\x61\
\x6d\x65\x64\x53\x69\x6d\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\
\x84\x84\xb3\x12\x4e\x61\x6d\x65\x64\x53\x69\x6d\x70\x6c\x65\x50\
\x61\x74\x74\x65\x72\x6e\xb4\xb3\x02\x6f\x72\xb5\xb5\xb1\x05\x6e\
\x61\x6d\x65\x64\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x07\x42\x69\
\x6e\x64\x69\x6e\x67\x84\x84\xb5\xb1\x09\x61\x6e\x6f\x6e\x79\x6d\
\x6f\x75\x73\xb4\xb3\x03\x72\x65\x66\xb5\x84\xb3\x0d\x53\x69\x6d\
\x70\x6c\x65\x50\x61\x74\x74\x65\x72\x6e\x84\x84\x84\x84\x84\xb3\
\x0c\x65\x6d\x62\x65\x64\x64\x65\x64\x54\x79\x70\x65\x80\x84\x84\
\x84\x84"
} }

View File

@ -50,7 +50,7 @@ mod dom {
.wrap(); .wrap();
assert_eq!( assert_eq!(
PackedWriter::encode_iovalue(&v.copy_via(&mut dom_as_preserves).unwrap()).unwrap(), PackedWriter::encode_iovalue(&v.copy_via(&mut dom_as_preserves).unwrap()).unwrap(),
[0xb5, 0x91, 0xb2, 0x04, 255, 255, 255, 255, 0x92, 0x84] [0xb5, 0xb0, 0x01, 0x01, 0xb2, 0x04, 255, 255, 255, 255, 0xb0, 0x01, 0x02, 0x84]
); );
} }
@ -64,7 +64,7 @@ mod dom {
.wrap(); .wrap();
assert_eq!( assert_eq!(
PackedWriter::encode_iovalue(&v.copy_via(&mut dom_as_preserves).unwrap()).unwrap(), PackedWriter::encode_iovalue(&v.copy_via(&mut dom_as_preserves).unwrap()).unwrap(),
[0xb5, 0x91, 0xb3, 0x08, 68, 111, 109, 58, 58, 84, 119, 111, 0x92, 0x84] [0xb5, 0xb0, 0x01, 0x01, 0xb3, 0x08, 68, 111, 109, 58, 58, 84, 119, 111, 0xb0, 0x01, 0x02, 0x84]
); );
} }
} }
@ -507,7 +507,7 @@ mod decoder_tests {
#[test] #[test]
fn skip_annotations_noskip() { fn skip_annotations_noskip() {
let buf = &b"\x85\x92\x91"[..]; let buf = &b"\x85\xB0\x01\x02\xB0\x01\x01"[..];
let mut src = BytesBinarySource::new(&buf); let mut src = BytesBinarySource::new(&buf);
let mut d = ConfiguredReader::new(src.packed_iovalues()); let mut d = ConfiguredReader::new(src.packed_iovalues());
let v = d.demand_next().unwrap(); let v = d.demand_next().unwrap();
@ -518,7 +518,7 @@ mod decoder_tests {
#[test] #[test]
fn skip_annotations_skip() { fn skip_annotations_skip() {
let buf = &b"\x85\x92\x91"[..]; let buf = &b"\x85\xB0\x01\x02\xB0\x01\x01"[..];
let mut src = BytesBinarySource::new(&buf); let mut src = BytesBinarySource::new(&buf);
let mut d = ConfiguredReader::new(src.packed_iovalues()); let mut d = ConfiguredReader::new(src.packed_iovalues());
d.set_read_annotations(false); d.set_read_annotations(false);
@ -554,60 +554,60 @@ mod decoder_tests {
#[test] #[test]
fn direct_i8_format_a_positive() { fn direct_i8_format_a_positive() {
assert_eq!(from_bytes::<i8>(b"\x91").unwrap(), 1) assert_eq!(from_bytes::<i8>(b"\xB0\x01\x01").unwrap(), 1)
} }
#[test] #[test]
fn direct_i8_format_a_zero() { fn direct_i8_format_a_zero() {
assert_eq!(from_bytes::<i8>(b"\x90").unwrap(), 0) assert_eq!(from_bytes::<i8>(b"\xB0\x00").unwrap(), 0)
} }
#[test] #[test]
fn direct_i8_format_a_negative() { fn direct_i8_format_a_negative() {
assert_eq!(from_bytes::<i8>(b"\x9f").unwrap(), -1) assert_eq!(from_bytes::<i8>(b"\xB0\x01\xff").unwrap(), -1)
} }
#[test] #[test]
fn direct_i8_format_b() { fn direct_i8_format_b() {
assert_eq!(from_bytes::<i8>(b"\xa0\xfe").unwrap(), -2) assert_eq!(from_bytes::<i8>(b"\xb0\x01\xfe").unwrap(), -2)
} }
#[test] #[test]
fn direct_i8_format_b_too_long() { fn direct_i8_format_b_too_long() {
assert_eq!(from_bytes::<i8>(b"\xa2\xff\xff\xfe").unwrap(), -2) assert_eq!(from_bytes::<i8>(b"\xb0\x03\xff\xff\xfe").unwrap(), -2)
} }
#[test] #[test]
fn direct_i8_format_b_much_too_long() { fn direct_i8_format_b_much_too_long() {
assert_eq!( assert_eq!(
from_bytes::<i8>(b"\xa9\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe").unwrap(), from_bytes::<i8>(b"\xb0\x0a\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe").unwrap(),
-2 -2
) )
} }
#[test] #[test]
fn direct_u8_format_a_positive() { fn direct_u8_format_a_positive() {
assert_eq!(from_bytes::<u8>(b"\x91").unwrap(), 1) assert_eq!(from_bytes::<u8>(b"\xB0\x01\x01").unwrap(), 1)
} }
#[test] #[test]
fn direct_u8_format_a_zero() { fn direct_u8_format_a_zero() {
assert_eq!(from_bytes::<u8>(b"\x90").unwrap(), 0) assert_eq!(from_bytes::<u8>(b"\xB0\x00").unwrap(), 0)
} }
#[test] #[test]
fn direct_u8_format_b() { fn direct_u8_format_b() {
assert_eq!(from_bytes::<u8>(b"\xa01").unwrap(), 49) assert_eq!(from_bytes::<u8>(b"\xb0\x011").unwrap(), 49)
} }
#[test] #[test]
fn direct_u8_format_b_too_long() { fn direct_u8_format_b_too_long() {
assert_eq!(from_bytes::<u8>(b"\xa3\0\0\01").unwrap(), 49) assert_eq!(from_bytes::<u8>(b"\xb0\x04\0\0\01").unwrap(), 49)
} }
#[test] #[test]
fn direct_u8_format_b_much_too_long() { fn direct_u8_format_b_much_too_long() {
assert_eq!(from_bytes::<u8>(b"\xa9\0\0\0\0\0\0\0\0\01").unwrap(), 49) assert_eq!(from_bytes::<u8>(b"\xb0\x0a\0\0\0\0\0\0\0\0\01").unwrap(), 49)
} }
#[test] #[test]
fn direct_i16_format_a() { fn direct_i16_format_a() {
assert_eq!(from_bytes::<i16>(b"\x9e").unwrap(), -2) assert_eq!(from_bytes::<i16>(b"\xB0\x01\xfe").unwrap(), -2)
} }
#[test] #[test]
fn direct_i16_format_b() { fn direct_i16_format_b() {
assert_eq!(from_bytes::<i16>(b"\xa1\xfe\xff").unwrap(), -257) assert_eq!(from_bytes::<i16>(b"\xb0\x02\xfe\xff").unwrap(), -257)
} }
#[test] #[test]
@ -620,141 +620,141 @@ mod decoder_tests {
#[test] #[test]
fn direct_u8_format_b_too_large() { fn direct_u8_format_b_too_large() {
expect_number_out_of_range(from_bytes::<u8>(b"\xa3\0\011")) expect_number_out_of_range(from_bytes::<u8>(b"\xb0\x04\0\011"))
} }
#[test] #[test]
fn direct_i8_format_b_too_large() { fn direct_i8_format_b_too_large() {
expect_number_out_of_range(from_bytes::<i8>(b"\xa1\xfe\xff")) expect_number_out_of_range(from_bytes::<i8>(b"\xb0\x02\xfe\xff"))
} }
#[test] #[test]
fn direct_i16_format_b_too_large() { fn direct_i16_format_b_too_large() {
expect_number_out_of_range(from_bytes::<i16>(b"\xa2\xfe\xff\xff")); expect_number_out_of_range(from_bytes::<i16>(b"\xb0\x03\xfe\xff\xff"));
} }
#[test] #[test]
fn direct_i32_format_b_ok() { fn direct_i32_format_b_ok() {
assert_eq!(from_bytes::<i32>(b"\xa2\xfe\xff\xff").unwrap(), -65537); assert_eq!(from_bytes::<i32>(b"\xb0\x03\xfe\xff\xff").unwrap(), -65537);
} }
#[test] #[test]
fn direct_i32_format_b_ok_2() { fn direct_i32_format_b_ok_2() {
assert_eq!( assert_eq!(
from_bytes::<i32>(b"\xa3\xfe\xff\xff\xff").unwrap(), from_bytes::<i32>(b"\xb0\x04\xfe\xff\xff\xff").unwrap(),
-16777217 -16777217
); );
} }
#[test] #[test]
fn direct_i64_format_b() { fn direct_i64_format_b() {
assert_eq!(from_bytes::<i64>(b"\xa0\xff").unwrap(), -1); assert_eq!(from_bytes::<i64>(b"\xb0\x01\xff").unwrap(), -1);
assert_eq!(from_bytes::<i64>(b"\xa2\xff\xff\xff").unwrap(), -1); assert_eq!(from_bytes::<i64>(b"\xb0\x03\xff\xff\xff").unwrap(), -1);
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa9\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x0a\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff").unwrap(),
-1 -1
); );
assert_eq!(from_bytes::<i64>(b"\xa0\xfe").unwrap(), -2); assert_eq!(from_bytes::<i64>(b"\xb0\x01\xfe").unwrap(), -2);
assert_eq!(from_bytes::<i64>(b"\xa2\xff\xfe\xff").unwrap(), -257); assert_eq!(from_bytes::<i64>(b"\xb0\x03\xff\xfe\xff").unwrap(), -257);
assert_eq!(from_bytes::<i64>(b"\xa2\xfe\xff\xff").unwrap(), -65537); assert_eq!(from_bytes::<i64>(b"\xb0\x03\xfe\xff\xff").unwrap(), -65537);
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa9\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x0a\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff").unwrap(),
-16777217 -16777217
); );
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa9\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x0a\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff").unwrap(),
-72057594037927937 -72057594037927937
); );
expect_number_out_of_range(from_bytes::<i64>( expect_number_out_of_range(from_bytes::<i64>(
b"\xa9\xff\xff\x0e\xff\xff\xff\xff\xff\xff\xff", b"\xb0\x0a\xff\xff\x0e\xff\xff\xff\xff\xff\xff\xff",
)); ));
expect_number_out_of_range(from_bytes::<i64>( expect_number_out_of_range(from_bytes::<i64>(
b"\xa8\xff\x0e\xff\xff\xff\xff\xff\xff\xff", b"\xb0\x09\xff\x0e\xff\xff\xff\xff\xff\xff\xff",
)); ));
expect_number_out_of_range(from_bytes::<i64>( expect_number_out_of_range(from_bytes::<i64>(
b"\xa8\x80\x0e\xff\xff\xff\xff\xff\xff\xff", b"\xb0\x09\x80\x0e\xff\xff\xff\xff\xff\xff\xff",
)); ));
expect_number_out_of_range(from_bytes::<i64>( expect_number_out_of_range(from_bytes::<i64>(
b"\xa9\xff\x00\x0e\xff\xff\xff\xff\xff\xff\xff", b"\xb0\x0a\xff\x00\x0e\xff\xff\xff\xff\xff\xff\xff",
)); ));
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa7\xfe\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x08\xfe\xff\xff\xff\xff\xff\xff\xff").unwrap(),
-72057594037927937 -72057594037927937
); );
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa7\x0e\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x08\x0e\xff\xff\xff\xff\xff\xff\xff").unwrap(),
1080863910568919039 1080863910568919039
); );
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa7\x80\0\0\0\0\0\0\0").unwrap(), from_bytes::<i64>(b"\xb0\x08\x80\0\0\0\0\0\0\0").unwrap(),
-9223372036854775808 -9223372036854775808
); );
assert_eq!(from_bytes::<i64>(b"\xa7\0\0\0\0\0\0\0\0").unwrap(), 0); assert_eq!(from_bytes::<i64>(b"\xb0\x08\0\0\0\0\0\0\0\0").unwrap(), 0);
assert_eq!(from_bytes::<i64>(b"\x90").unwrap(), 0); assert_eq!(from_bytes::<i64>(b"\xB0\x00").unwrap(), 0);
assert_eq!( assert_eq!(
from_bytes::<i64>(b"\xa7\x7f\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<i64>(b"\xb0\x08\x7f\xff\xff\xff\xff\xff\xff\xff").unwrap(),
9223372036854775807 9223372036854775807
); );
} }
#[test] #[test]
fn direct_u64_format_b() { fn direct_u64_format_b() {
expect_number_out_of_range(from_bytes::<u64>(b"\xa0\xff")); expect_number_out_of_range(from_bytes::<u64>(b"\xb0\x01\xff"));
assert_eq!(from_bytes::<u64>(b"\xa1\0\xff").unwrap(), 255); assert_eq!(from_bytes::<u64>(b"\xb0\x02\0\xff").unwrap(), 255);
expect_number_out_of_range(from_bytes::<u64>(b"\xa2\xff\xff\xff")); expect_number_out_of_range(from_bytes::<u64>(b"\xb0\x03\xff\xff\xff"));
assert_eq!(from_bytes::<u64>(b"\xa3\0\xff\xff\xff").unwrap(), 0xffffff); assert_eq!(from_bytes::<u64>(b"\xb0\x04\0\xff\xff\xff").unwrap(), 0xffffff);
expect_number_out_of_range(from_bytes::<u64>( expect_number_out_of_range(from_bytes::<u64>(
b"\xa9\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", b"\xb0\x0a\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff",
)); ));
assert_eq!(from_bytes::<u64>(b"\xa0\x02").unwrap(), 2); assert_eq!(from_bytes::<u64>(b"\xb0\x01\x02").unwrap(), 2);
assert_eq!(from_bytes::<u64>(b"\xa2\x00\x01\x00").unwrap(), 256); assert_eq!(from_bytes::<u64>(b"\xb0\x03\x00\x01\x00").unwrap(), 256);
assert_eq!(from_bytes::<u64>(b"\xa2\x01\x00\x00").unwrap(), 65536); assert_eq!(from_bytes::<u64>(b"\xb0\x03\x01\x00\x00").unwrap(), 65536);
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa9\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x0a\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00").unwrap(),
16777216 16777216
); );
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa9\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x0a\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00").unwrap(),
72057594037927936 72057594037927936
); );
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa9\x00\x00\xf2\x00\x00\x00\x00\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x0a\x00\x00\xf2\x00\x00\x00\x00\x00\x00\x00").unwrap(),
0xf200000000000000 0xf200000000000000
); );
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa9\x00\x00\x72\x00\x00\x00\x00\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x0a\x00\x00\x72\x00\x00\x00\x00\x00\x00\x00").unwrap(),
0x7200000000000000 0x7200000000000000
); );
expect_number_out_of_range(from_bytes::<u64>( expect_number_out_of_range(from_bytes::<u64>(
b"\xa9\x00\xf2\x00\x00\x00\x00\x00\x00\x00\x00", b"\xb0\x0a\x00\xf2\x00\x00\x00\x00\x00\x00\x00\x00",
)); ));
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa8\x00\xf2\x00\x00\x00\x00\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x09\x00\xf2\x00\x00\x00\x00\x00\x00\x00").unwrap(),
0xf200000000000000 0xf200000000000000
); );
expect_number_out_of_range(from_bytes::<u64>( expect_number_out_of_range(from_bytes::<u64>(
b"\xa8\x7f\xf2\x00\x00\x00\x00\x00\x00\x00", b"\xb0\x09\x7f\xf2\x00\x00\x00\x00\x00\x00\x00",
)); ));
expect_number_out_of_range(from_bytes::<u64>( expect_number_out_of_range(from_bytes::<u64>(
b"\xa9\x00\xff\xf2\x00\x00\x00\x00\x00\x00\x00", b"\xb0\x0a\x00\xff\xf2\x00\x00\x00\x00\x00\x00\x00",
)); ));
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa7\x01\x00\x00\x00\x00\x00\x00\x00").unwrap(), from_bytes::<u64>(b"\xb0\x08\x01\x00\x00\x00\x00\x00\x00\x00").unwrap(),
72057594037927936 72057594037927936
); );
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa7\x0e\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<u64>(b"\xb0\x08\x0e\xff\xff\xff\xff\xff\xff\xff").unwrap(),
1080863910568919039 1080863910568919039
); );
expect_number_out_of_range(from_bytes::<u64>(b"\xa7\x80\0\0\0\0\0\0\0")); expect_number_out_of_range(from_bytes::<u64>(b"\xb0\x08\x80\0\0\0\0\0\0\0"));
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa8\0\x80\0\0\0\0\0\0\0").unwrap(), from_bytes::<u64>(b"\xb0\x09\0\x80\0\0\0\0\0\0\0").unwrap(),
9223372036854775808 9223372036854775808
); );
assert_eq!(from_bytes::<u64>(b"\xa7\0\0\0\0\0\0\0\0").unwrap(), 0); assert_eq!(from_bytes::<u64>(b"\xb0\x08\0\0\0\0\0\0\0\0").unwrap(), 0);
assert_eq!(from_bytes::<u64>(b"\x90").unwrap(), 0); assert_eq!(from_bytes::<u64>(b"\xB0\x00").unwrap(), 0);
assert_eq!( assert_eq!(
from_bytes::<u64>(b"\xa7\x7f\xff\xff\xff\xff\xff\xff\xff").unwrap(), from_bytes::<u64>(b"\xb0\x08\x7f\xff\xff\xff\xff\xff\xff\xff").unwrap(),
9223372036854775807 9223372036854775807
); );
} }
@ -927,17 +927,17 @@ mod serde_tests {
0x81, // true 0x81, // true
0x84, 0xb6, // Set 0x84, 0xb6, // Set
0xb1, 0x03, 0x6f, 0x6e, 0x65, 0xb1, 0x03, 0x74, 0x77, 0x6f, 0xb1, 0x05, 0x74, 0x68, 0xb1, 0x03, 0x6f, 0x6e, 0x65, 0xb1, 0x03, 0x74, 0x77, 0x6f, 0xb1, 0x05, 0x74, 0x68,
0x72, 0x65, 0x65, 0x84, 0xa1, 0x30, 0x39, // 12345 0x72, 0x65, 0x65, 0x84, 0xb0, 0x02, 0x30, 0x39, // 12345
0xb1, 0x02, 0x68, 0x69, // "hi" 0xb1, 0x02, 0x68, 0x69, // "hi"
0xb7, // Dictionary 0xb7, // Dictionary
0xb1, 0x03, 0x72, 0x65, 0x64, // "red" 0xb1, 0x03, 0x72, 0x65, 0x64, // "red"
0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0xa1, 0x00, 0xff, 0x90, 0x90, 0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0xb0, 0x02, 0x00, 0xff, 0xb0, 0x00, 0xb0, 0x00,
0x84, 0xb1, 0x04, 0x62, 0x6c, 0x75, 0x65, // "blue" 0x84, 0xb1, 0x04, 0x62, 0x6c, 0x75, 0x65, // "blue"
0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x90, 0x90, 0xa1, 0x00, 0xff, 0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0xb0, 0x00, 0xb0, 0x00, 0xb0, 0x02, 0x00, 0xff,
0x84, 0xb1, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6e, // "green" 0x84, 0xb1, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6e, // "green"
0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x90, 0xa1, 0x00, 0xff, 0x90, 0xb4, 0xb3, 0x06, 0x43, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0xb0, 0x00, 0xb0, 0x02, 0x00, 0xff, 0xb0, 0x00,
0x84, 0x84, 0x82, 0x41, 0x45, 0x85, 0x1f, // 12.345, 0x84, 0x84, 0x87, 0x04, 0x41, 0x45, 0x85, 0x1f, // 12.345,
0x83, 0x40, 0x28, 0xb0, 0xfc, 0xd3, 0x24, 0xd5, 0xa2, // 12.3456789 0x87, 0x08, 0x40, 0x28, 0xb0, 0xfc, 0xd3, 0x24, 0xd5, 0xa2, // 12.3456789
0x84, 0x84,
]; ];

View File

@ -6,6 +6,8 @@ pub struct Type {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Item { pub enum Item {
Annotation,
AnnotatedValue,
DictionaryKey, DictionaryKey,
DictionaryValue, DictionaryValue,
RecordField, RecordField,

View File

@ -6,6 +6,7 @@ pub enum Tag {
False, False,
True, True,
End, End,
Annotation,
Embedded, Embedded,
Ieee754, Ieee754,
SignedInteger, SignedInteger,
@ -16,7 +17,6 @@ pub enum Tag {
Sequence, Sequence,
Set, Set,
Dictionary, Dictionary,
Annotated,
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -44,6 +44,7 @@ impl TryFrom<u8> for Tag {
0x80 => Ok(Self::False), 0x80 => Ok(Self::False),
0x81 => Ok(Self::True), 0x81 => Ok(Self::True),
0x84 => Ok(Self::End), 0x84 => Ok(Self::End),
0x85 => Ok(Self::Annotation),
0x86 => Ok(Self::Embedded), 0x86 => Ok(Self::Embedded),
0x87 => Ok(Self::Ieee754), 0x87 => Ok(Self::Ieee754),
0xb0 => Ok(Self::SignedInteger), 0xb0 => Ok(Self::SignedInteger),
@ -54,7 +55,6 @@ impl TryFrom<u8> for Tag {
0xb5 => Ok(Self::Sequence), 0xb5 => Ok(Self::Sequence),
0xb6 => Ok(Self::Set), 0xb6 => Ok(Self::Set),
0xb7 => Ok(Self::Dictionary), 0xb7 => Ok(Self::Dictionary),
0xbf => Ok(Self::Annotated),
_ => Err(InvalidTag(v)), _ => Err(InvalidTag(v)),
} }
} }
@ -66,6 +66,7 @@ impl From<Tag> for u8 {
Tag::False => 0x80, Tag::False => 0x80,
Tag::True => 0x81, Tag::True => 0x81,
Tag::End => 0x84, Tag::End => 0x84,
Tag::Annotation => 0x85,
Tag::Embedded => 0x86, Tag::Embedded => 0x86,
Tag::Ieee754 => 0x87, Tag::Ieee754 => 0x87,
Tag::SignedInteger => 0xb0, Tag::SignedInteger => 0xb0,
@ -76,7 +77,6 @@ impl From<Tag> for u8 {
Tag::Sequence => 0xb5, Tag::Sequence => 0xb5,
Tag::Set => 0xb6, Tag::Set => 0xb6,
Tag::Dictionary => 0xb7, Tag::Dictionary => 0xb7,
Tag::Annotated => 0xbf,
} }
} }
} }

View File

@ -120,49 +120,42 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
F: FnOnce(&mut Self, Tag) -> ReaderResult<T>, F: FnOnce(&mut Self, Tag) -> ReaderResult<T>,
{ {
let m = self.source.mark()?; let m = self.source.mark()?;
match Tag::try_from(self.peek()?)? { loop {
Tag::Annotated => { match Tag::try_from(self.peek()?)? {
self.skip()?; Tag::Annotation => {
match f(self, Tag::try_from(self.peek()?)?) { self.skip()?;
Ok(v) => { self.skip_value()?;
self.skip_annotations()?; }
Ok(v) tag => match f(self, tag) {
} Ok(v) => return Ok(v),
Err(e) => { Err(e) => {
self.source.restore(&m)?; self.source.restore(&m)?;
Err(e) return Err(e);
} }
} }
} }
other => match f(self, other) {
Ok(v) => Ok(v),
Err(e) => {
self.source.restore(&m)?;
Err(e)
}
}
} }
} }
fn next_atomic(&mut self, expected_tag: Tag, k: ExpectedKind) -> ReaderResult<Cow<'de, [u8]>> { fn next_atomic(&mut self, expected_tag: Tag, k: ExpectedKind) -> ReaderResult<Cow<'de, [u8]>> {
self.try_next_nonannotation(|_, actual_tag| { self.try_next_nonannotation(|r, actual_tag| {
if actual_tag == expected_tag { if actual_tag == expected_tag {
self.skip()?; r.skip()?;
let count = self.varint()?; let count = r.varint()?;
Ok(self.readbytes(count)?) Ok(r.readbytes(count)?)
} else { } else {
Err(self.expected(k)) Err(r.expected(k))
} }
}) })
} }
fn next_compound(&mut self, expected_tag: Tag, k: ExpectedKind) -> ReaderResult<()> { fn next_compound(&mut self, expected_tag: Tag, k: ExpectedKind) -> ReaderResult<()> {
self.try_next_nonannotation(|_, actual_tag| { self.try_next_nonannotation(|r, actual_tag| {
if actual_tag == expected_tag { if actual_tag == expected_tag {
self.skip()?; r.skip()?;
Ok(()) Ok(())
} else { } else {
Err(self.expected(k)) Err(r.expected(k))
} }
}) })
} }
@ -222,16 +215,16 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
where where
F: FnOnce(u128) -> Option<T>, F: FnOnce(u128) -> Option<T>,
{ {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
match tag { match tag {
Tag::SignedInteger => { Tag::SignedInteger => {
self.skip()?; r.skip()?;
let count = self.varint()?; let count = r.varint()?;
let n = &self.read_signed_integer(count)?; let n = &r.read_signed_integer(count)?;
let i = n.try_into().map_err(|_| out_of_range(n))?; let i = n.try_into().map_err(|_| out_of_range(n))?;
f(i).ok_or_else(|| out_of_range(i)) f(i).ok_or_else(|| out_of_range(i))
} }
_ => Err(self.expected(ExpectedKind::SignedInteger)), _ => Err(r.expected(ExpectedKind::SignedInteger)),
} }
}) })
} }
@ -241,23 +234,34 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
where where
F: FnOnce(i128) -> Option<T>, F: FnOnce(i128) -> Option<T>,
{ {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
match tag { match tag {
Tag::SignedInteger => { Tag::SignedInteger => {
self.skip()?; r.skip()?;
let count = self.varint()?; let count = r.varint()?;
let n = &self.read_signed_integer(count)?; let n = &r.read_signed_integer(count)?;
let i = n.try_into().map_err(|_| out_of_range(n))?; let i = n.try_into().map_err(|_| out_of_range(n))?;
f(i).ok_or_else(|| out_of_range(i)) f(i).ok_or_else(|| out_of_range(i))
} }
_ => Err(self.expected(ExpectedKind::SignedInteger)), _ => Err(r.expected(ExpectedKind::SignedInteger)),
} }
}) })
} }
fn gather_annotations(&mut self) -> io::Result<Vec<N>> {
let mut annotations = vec![self.demand_next(true)?];
while Tag::try_from(self.peek()?)? == Tag::Annotation {
self.skip()?;
annotations.push(self.demand_next(true)?);
}
Ok(annotations)
}
fn skip_annotations(&mut self) -> io::Result<()> { fn skip_annotations(&mut self) -> io::Result<()> {
while !self.peekend()? { self.skip_value()?;
self.skip_value()? while Tag::try_from(self.peek()?)? == Tag::Annotation {
self.skip()?;
self.skip_value()?;
} }
Ok(()) Ok(())
} }
@ -282,6 +286,17 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
Ok(Some(match Tag::try_from(self.read()?)? { Ok(Some(match Tag::try_from(self.read()?)? {
Tag::False => N::new(false), Tag::False => N::new(false),
Tag::True => N::new(true), Tag::True => N::new(true),
Tag::Annotation => {
if read_annotations {
let mut annotations = self.gather_annotations()?;
let (existing_annotations, v) = self.demand_next(read_annotations)?.pieces();
annotations.extend_from_slice(existing_annotations.slice());
N::wrap(Annotations::new(Some(annotations)), v)
} else {
self.skip_annotations()?;
self.demand_next(read_annotations)?
}
}
Tag::Embedded => Value::Embedded( Tag::Embedded => Value::Embedded(
self.decode_embedded self.decode_embedded
.decode_embedded(self.source, read_annotations)?, .decode_embedded(self.source, read_annotations)?,
@ -297,7 +312,7 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
self.readbytes_into(&mut bs)?; self.readbytes_into(&mut bs)?;
Value::from(f64::from_bits(u64::from_be_bytes(bs))).wrap() Value::from(f64::from_bits(u64::from_be_bytes(bs))).wrap()
} }
_ => return Err(io_syntax_error("Invalid IEEE754 size")), _ => return Err(io_syntax_error("Invalid IEEE754 size"))
} }
Tag::SignedInteger => { Tag::SignedInteger => {
let count = self.varint()?; let count = self.varint()?;
@ -352,28 +367,6 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
} }
Value::Dictionary(d).wrap() Value::Dictionary(d).wrap()
} }
Tag::Annotated => {
match self.next_upto_end(read_annotations)? {
None => return Err(io_syntax_error("Missing underlying annotated value")),
Some(underlying) => {
if read_annotations {
let mut annotations = Vec::new();
while let Some(v) = self.next_upto_end(read_annotations)? {
annotations.push(v);
}
if annotations.is_empty() {
return Err(io_syntax_error("Too few annotations in annotated value"));
}
let (existing_annotations, v) = underlying.pieces();
annotations.extend_from_slice(existing_annotations.slice());
N::wrap(Annotations::new(Some(annotations)), v)
} else {
self.skip_annotations()?;
underlying
}
}
}
}
tag @ Tag::End => { tag @ Tag::End => {
return Err(io_syntax_error(&format!("Invalid tag: {:?}", tag))); return Err(io_syntax_error(&format!("Invalid tag: {:?}", tag)));
} }
@ -390,17 +383,17 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
#[inline(always)] #[inline(always)]
fn open_sequence_or_set(&mut self) -> ReaderResult<B::Item> { fn open_sequence_or_set(&mut self) -> ReaderResult<B::Item> {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
match tag { match tag {
Tag::Sequence => { Tag::Sequence => {
self.skip()?; r.skip()?;
Ok(B::Item::SequenceValue) Ok(B::Item::SequenceValue)
} }
Tag::Set => { Tag::Set => {
self.skip()?; r.skip()?;
Ok(B::Item::SetValue) Ok(B::Item::SetValue)
} }
_ => Err(self.expected(ExpectedKind::SequenceOrSet)), _ => Err(r.expected(ExpectedKind::SequenceOrSet)),
} }
}) })
} }
@ -420,14 +413,6 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
self.next_compound(Tag::Dictionary, ExpectedKind::Dictionary) self.next_compound(Tag::Dictionary, ExpectedKind::Dictionary)
} }
#[inline(always)]
fn open_annotations(&mut self, annotations: Option<&mut Vec<N>>) -> ReaderResult<()> {
}
#[inline(always)]
fn close_annotations(&mut self, annotations: Option<&mut Vec<N>>) -> ReaderResult<()> {
}
#[inline(always)] #[inline(always)]
fn boundary(&mut self, _b: &B::Type) -> ReaderResult<()> { fn boundary(&mut self, _b: &B::Type) -> ReaderResult<()> {
Ok(()) Ok(())
@ -461,74 +446,91 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
} }
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> { fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> {
Ok(match Tag::try_from(self.peek()?)? { loop {
Tag::Embedded => { return Ok(match Tag::try_from(self.peek()?)? {
self.skip()?; Tag::Embedded => {
Token::Embedded( self.skip()?;
self.decode_embedded Token::Embedded(
.decode_embedded(self.source, read_embedded_annotations)?, self.decode_embedded
) .decode_embedded(self.source, read_embedded_annotations)?,
} )
Tag::False }
| Tag::True Tag::False
| Tag::Ieee754 | Tag::True
| Tag::SignedInteger | Tag::Ieee754
| Tag::String | Tag::SignedInteger
| Tag::ByteString | Tag::String
| Tag::Symbol => Token::Atom(self.demand_next(false)?), | Tag::ByteString
| Tag::Symbol => Token::Atom(self.demand_next(false)?),
Tag::Record => { Tag::Record => {
self.skip()?; self.skip()?;
Token::Compound(CompoundClass::Record) Token::Compound(CompoundClass::Record)
} }
Tag::Sequence => { Tag::Sequence => {
self.skip()?; self.skip()?;
Token::Compound(CompoundClass::Sequence) Token::Compound(CompoundClass::Sequence)
} }
Tag::Set => { Tag::Set => {
self.skip()?; self.skip()?;
Token::Compound(CompoundClass::Set) Token::Compound(CompoundClass::Set)
} }
Tag::Dictionary => { Tag::Dictionary => {
self.skip()?; self.skip()?;
Token::Compound(CompoundClass::Dictionary) Token::Compound(CompoundClass::Dictionary)
} }
Tag::End => { Tag::End => {
self.skip()?; self.skip()?;
Token::End Token::End
} }
Tag::Annotated => Token::AnnotationStart, Tag::Annotation => {
}) self.skip()?;
self.skip_value()?;
continue;
}
});
}
}
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)> {
match Tag::try_from(self.peek()?)? {
Tag::Annotation => {
self.skip()?;
let annotations = self.gather_annotations()?;
Ok((annotations, self.next_token(true)?))
}
_ => Ok((Vec::new(), self.next_token(true)?)),
}
} }
#[inline(always)] #[inline(always)]
fn next_boolean(&mut self) -> ReaderResult<bool> { fn next_boolean(&mut self) -> ReaderResult<bool> {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
match tag { match tag {
Tag::False => { Tag::False => {
self.skip()?; r.skip()?;
Ok(false) Ok(false)
} },
Tag::True => { Tag::True => {
self.skip()?; r.skip()?;
Ok(true) Ok(true)
} },
_ => Err(self.expected(ExpectedKind::Boolean)), _ => Err(r.expected(ExpectedKind::Boolean)),
} }
}) })
} }
fn next_signedinteger(&mut self) -> ReaderResult<SignedInteger> { fn next_signedinteger(&mut self) -> ReaderResult<SignedInteger> {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
match tag { match tag {
Tag::SignedInteger => { Tag::SignedInteger => {
self.skip()?; r.skip()?;
let count = self.varint()?; let count = r.varint()?;
Ok(self.read_signed_integer(count)?) Ok(r.read_signed_integer(count)?)
} }
_ => Err(self.expected(ExpectedKind::SignedInteger)), _ => Err(r.expected(ExpectedKind::SignedInteger)),
} }
}) })
} }
@ -566,48 +568,47 @@ impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::Embedded>, S: BinarySource<
} }
fn next_f32(&mut self) -> ReaderResult<f32> { fn next_f32(&mut self) -> ReaderResult<f32> {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
if tag == Tag::Ieee754 { if tag == Tag::Ieee754 {
match self.varint()? { r.skip()?;
match r.varint()? {
4 => { 4 => {
let mut bs = [0; 4]; let mut bs = [0; 4];
self.readbytes_into(&mut bs)?; r.readbytes_into(&mut bs)?;
Ok(f32::from_bits(u32::from_be_bytes(bs))) Ok(f32::from_bits(u32::from_be_bytes(bs)))
} }
8 => { 8 => {
self.skip()?;
let mut bs = [0; 8]; let mut bs = [0; 8];
self.readbytes_into(&mut bs)?; r.readbytes_into(&mut bs)?;
Ok(f64::from_bits(u64::from_be_bytes(bs)) as f32) Ok(f64::from_bits(u64::from_be_bytes(bs)) as f32)
} }
_ => Err(io_syntax_error("Invalid IEEE754 size"))?, _ => Err(io_syntax_error("Invalid IEEE754 size"))?,
} }
} else { } else {
Err(self.expected(ExpectedKind::Float)) Err(r.expected(ExpectedKind::Float))
} }
}) })
} }
fn next_f64(&mut self) -> ReaderResult<f64> { fn next_f64(&mut self) -> ReaderResult<f64> {
self.try_next_nonannotation(|_, tag| { self.try_next_nonannotation(|r, tag| {
if tag == Tag::Ieee754 { if tag == Tag::Ieee754 {
match self.varint()? { r.skip()?;
match r.varint()? {
4 => { 4 => {
self.skip()?;
let mut bs = [0; 4]; let mut bs = [0; 4];
self.readbytes_into(&mut bs)?; r.readbytes_into(&mut bs)?;
Ok(f32::from_bits(u32::from_be_bytes(bs)) as f64) Ok(f32::from_bits(u32::from_be_bytes(bs)) as f64)
} }
8 => { 8 => {
self.skip()?;
let mut bs = [0; 8]; let mut bs = [0; 8];
self.readbytes_into(&mut bs)?; r.readbytes_into(&mut bs)?;
Ok(f64::from_bits(u64::from_be_bytes(bs))) Ok(f64::from_bits(u64::from_be_bytes(bs)))
} }
_ => Err(io_syntax_error("Invalid IEEE754 size"))?, _ => Err(io_syntax_error("Invalid IEEE754 size"))?,
} }
} else { } else {
Err(self.expected(ExpectedKind::Double)) Err(r.expected(ExpectedKind::Double))
} }
}) })
} }

View File

@ -146,6 +146,9 @@ impl WriteWriter for BinaryOrderWriter {
impl<W: io::Write> CompoundWriter for PackedWriter<W> { impl<W: io::Write> CompoundWriter for PackedWriter<W> {
#[inline(always)] #[inline(always)]
fn boundary(&mut self, b: &B::Type) -> io::Result<()> { fn boundary(&mut self, b: &B::Type) -> io::Result<()> {
if let Some(B::Item::Annotation) = b.opening {
self.write_tag(Tag::Annotation)?;
}
Ok(()) Ok(())
} }
} }
@ -316,6 +319,9 @@ impl<W: io::Write> Writer for PackedWriter<W> {
#[inline(always)] #[inline(always)]
fn write_i8(&mut self, v: i8) -> io::Result<()> { fn write_i8(&mut self, v: i8) -> io::Result<()> {
if v == 0 {
return self.write_integer(&[]);
}
self.write_integer(&[v as u8]) self.write_integer(&[v as u8])
} }

View File

@ -40,14 +40,12 @@ pub trait Reader<'de, N: NestedValue> {
fn open_embedded(&mut self) -> ReaderResult<()>; fn open_embedded(&mut self) -> ReaderResult<()>;
fn close_embedded(&mut self) -> ReaderResult<()>; fn close_embedded(&mut self) -> ReaderResult<()>;
fn open_annotations(&mut self, annotations: Option<&mut Vec<N>>) -> ReaderResult<()>;
fn close_annotations(&mut self, annotations: Option<&mut Vec<N>>) -> ReaderResult<()>;
type Mark; type Mark;
fn mark(&mut self) -> io::Result<Self::Mark>; fn mark(&mut self) -> io::Result<Self::Mark>;
fn restore(&mut self, mark: &Self::Mark) -> io::Result<()>; fn restore(&mut self, mark: &Self::Mark) -> io::Result<()>;
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>>; fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>>;
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)>;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -250,6 +248,10 @@ impl<'r, 'de, N: NestedValue, R: Reader<'de, N>> Reader<'de, N> for &'r mut R {
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> { fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> {
(*self).next_token(read_embedded_annotations) (*self).next_token(read_embedded_annotations)
} }
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)> {
(*self).next_annotations_and_token()
}
} }
pub trait BinarySource<'de>: Sized { pub trait BinarySource<'de>: Sized {

View File

@ -29,7 +29,7 @@ information, and/or an ending tag may follow.
tag (simple atomic data) tag (simple atomic data)
tag ++ length ++ binarydata (floats, doubles, integers, strings, symbols, and binary) tag ++ length ++ binarydata (floats, doubles, integers, strings, symbols, and binary)
tag ++ repr ++ ... ++ endtag (compound data and annotations) tag ++ repr ++ ... ++ endtag (compound data)
The unique end tag is byte value `0x84`. The unique end tag is byte value `0x84`.
@ -138,22 +138,16 @@ represent the denoted object, prefixed with `[0x86]`.
### Annotations. ### Annotations.
«@V_1...@V_n V» = [0xBF] ++ «V» ++ «V_1» ++...++ «V_n» ++ [0x84] «@W V» = [0x85] ++ «W» «V»
`V` *MUST NOT* itself be annotated, but each `V_i` in `V_1...V_n` Each annotation precedes the `Value` it annotates. Implementations
*MAY* be annotated. Furthermore, `n` *MUST* be greater than zero. For *SHOULD* default to omitting annotations from binary `Repr`s. See
example, the `Repr` corresponding to textual syntax `@a@b[]`, i.e. an [examples in the appendix](#annotation-examples).
empty sequence annotated with two symbols, `a` and `b`, is
«@a @b []» = [0xBF] ++ «[]» ++ «a» ++ «b» ++ [0x84]
= [0xBF, 0xB5, 0x84, 0xB3, 0x01, 0x61, 0xB3, 0x01, 0x62, 0x84]
Implementations *SHOULD* default to omitting annotations from binary `Repr`s.
## Security Considerations ## Security Considerations
**Annotations.** In modes where a `Value` is being read while **Annotations.** In modes where a `Value` is being read while
annotations are skipped, an endless nesting of annotations may give an annotations are skipped, an endless series of annotations may give an
illusion of progress. illusion of progress.
**Canonical form for cryptographic hashing and signing.** No canonical **Canonical form for cryptographic hashing and signing.** No canonical
@ -184,6 +178,7 @@ a binary-syntax document; otherwise, it should be interpreted as text.
80 - False 80 - False
81 - True 81 - True
84 - End marker 84 - End marker
85 - Annotation
86 - Embedded 86 - Embedded
87 - Float and Double 87 - Float and Double
@ -196,11 +191,9 @@ a binary-syntax document; otherwise, it should be interpreted as text.
B6 - Set B6 - Set
B7 - Dictionary B7 - Dictionary
BF - Annotated Repr (not itself starting with BF) followed by annotations
All tags fall in the range [`0x80`, `0xBF`]. All tags fall in the range [`0x80`, `0xBF`].
Tag values `82`, `83`, `85`, `88`...`AF`, and `B8`...`BE` are **reserved**. Tag values `82`, `83`, `88`...`AF`, and `B8`...`BF` are **reserved**.
## Appendix. Binary SignedInteger representation ## Appendix. Binary SignedInteger representation
@ -220,7 +213,9 @@ values.
| -2<sup>55</sup> ≤ n < 2<sup>55</sup> (i56) | 9 | `B0` `07` `XX` `XX` `XX` `XX` `XX` `XX` `XX` | | -2<sup>55</sup> ≤ n < 2<sup>55</sup> (i56) | 9 | `B0` `07` `XX` `XX` `XX` `XX` `XX` `XX` `XX` |
| -2<sup>63</sup> ≤ n < 2<sup>63</sup> (i64) | 10 | `B0` `08` `XX` `XX` `XX` `XX` `XX` `XX` `XX` `XX` | | -2<sup>63</sup> ≤ n < 2<sup>63</sup> (i64) | 10 | `B0` `08` `XX` `XX` `XX` `XX` `XX` `XX` `XX` `XX` |
## <a id="signedinteger-examples"></a>Appendix. Binary SignedInteger examples ## Appendix. Examples
### <a id="signedinteger-examples"></a>Binary SignedInteger examples
«-257» = B0 02 FE FF «-2» = B0 01 FE «255» = B0 02 00 FF «-257» = B0 02 FE FF «-2» = B0 01 FE «255» = B0 02 00 FF
«-256» = B0 02 FF 00 «-1» = B0 01 FF «256» = B0 02 01 00 «-256» = B0 02 FF 00 «-1» = B0 01 FF «256» = B0 02 01 00
@ -234,5 +229,18 @@ values.
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00
### <a id="annotation-examples"></a>Annotation examples
The `Repr` corresponding to textual syntax `@a@b[]`, i.e. an empty
sequence annotated with two symbols, `a` and `b`, is
«@a @b []» = [0x85] ++ «a» ++ [0x85] ++ «b» ++ «[]»
= [0x85, 0xB3, 0x01, 0x61, 0x85, 0xB3, 0x01, 0x62, 0xB5, 0x84]
Annotations may themselves be annotated. Here, `c` is annotated with
`b`, which itself is annotated with `a`:
«@ @a b c» = [0x85] ++ [0x85] ++ «a» ++ «b» ++ «c»>
<!-- Heading to visually offset the footnotes from the main document: --> <!-- Heading to visually offset the footnotes from the main document: -->
## Notes ## Notes

View File

@ -756,7 +756,7 @@ suitable for placing into an <a class="autorefs autorefs-internal" href="../valu
</table> </table>
<p>Normal usage is to supply a buffer, and keep calling <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.next">next</a> <p>Normal usage is to supply a buffer, and keep calling <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.next">next</a>
until a <a class="autorefs autorefs-internal" href="../error/#preserves.error.ShortPacket">ShortPacket</a> exception is raised:</p> until a <a class="autorefs autorefs-internal" href="../error/#preserves.error.ShortPacket">ShortPacket</a> exception is raised:</p>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span><span class="p">)</span> <div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
<span class="mi">123</span> <span class="mi">123</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
@ -770,7 +770,7 @@ until a <a class="autorefs autorefs-internal" href="../error/#preserves.error.Sh
</code></pre></div> </code></pre></div>
<p>Alternatively, keep calling <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.try_next">try_next</a> until it yields <p>Alternatively, keep calling <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.try_next">try_next</a> until it yields
<code>None</code>, which is not in the domain of Preserves <code>Value</code>s:</p> <code>None</code>, which is not in the domain of Preserves <code>Value</code>s:</p>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span><span class="p">)</span> <div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">try_next</span><span class="p">()</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">try_next</span><span class="p">()</span>
<span class="mi">123</span> <span class="mi">123</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">try_next</span><span class="p">()</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">d</span><span class="o">.</span><span class="n">try_next</span><span class="p">()</span>
@ -782,18 +782,18 @@ until a <a class="autorefs autorefs-internal" href="../error/#preserves.error.Sh
<p>For convenience, <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder">Decoder</a> implements the iterator interface, <p>For convenience, <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder">Decoder</a> implements the iterator interface,
backing it with <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.try_next">try_next</a>, so you can simply iterate backing it with <a class="autorefs autorefs-internal" href="#preserves.binary.Decoder.try_next">try_next</a>, so you can simply iterate
over all complete values in an input:</p> over all complete values in an input:</p>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span><span class="p">)</span> <div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="o">&gt;&gt;&gt;</span> <span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="p">[</span><span class="mi">123</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">,</span> <span class="p">()]</span> <span class="p">[</span><span class="mi">123</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">,</span> <span class="p">()]</span>
</code></pre></div> </code></pre></div>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span><span class="p">):</span> <div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span><span class="p">):</span>
<span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">v</span><span class="p">))</span> <span class="o">...</span> <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">v</span><span class="p">))</span>
<span class="mi">123</span> <span class="mi">123</span>
<span class="s1">&#39;hello&#39;</span> <span class="s1">&#39;hello&#39;</span>
<span class="p">()</span> <span class="p">()</span>
</code></pre></div> </code></pre></div>
<p>Supply <code>include_annotations=True</code> to read annotations alongside the annotated values:</p> <p>Supply <code>include_annotations=True</code> to read annotations alongside the annotated values:</p>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">include_annotations</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="n">d</span> <span class="o">=</span> <span class="n">Decoder</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">include_annotations</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="p">)</span> <span class="o">&gt;&gt;&gt;</span> <span class="nb">list</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="p">[</span><span class="mi">123</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">,</span> <span class="o">@</span><span class="c1">#x ()]</span> <span class="p">[</span><span class="mi">123</span><span class="p">,</span> <span class="s1">&#39;hello&#39;</span><span class="p">,</span> <span class="o">@</span><span class="c1">#x ()]</span>
</code></pre></div> </code></pre></div>
@ -915,12 +915,7 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">184</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">189</span>
<span class="normal">185</span>
<span class="normal">186</span>
<span class="normal">187</span>
<span class="normal">188</span>
<span class="normal">189</span>
<span class="normal">190</span> <span class="normal">190</span>
<span class="normal">191</span> <span class="normal">191</span>
<span class="normal">192</span> <span class="normal">192</span>
@ -951,7 +946,10 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<span class="normal">217</span> <span class="normal">217</span>
<span class="normal">218</span> <span class="normal">218</span>
<span class="normal">219</span> <span class="normal">219</span>
<span class="normal">220</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="normal">220</span>
<span class="normal">221</span>
<span class="normal">222</span>
<span class="normal">223</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Reads the next complete `Value` from the internal buffer, raising</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Reads the next complete `Value` from the internal buffer, raising</span>
<span class="sd"> [ShortPacket][preserves.error.ShortPacket] if too few bytes are available, or</span> <span class="sd"> [ShortPacket][preserves.error.ShortPacket] if too few bytes are available, or</span>
<span class="sd"> [DecodeError][preserves.error.DecodeError] if the input is invalid somehow.</span> <span class="sd"> [DecodeError][preserves.error.DecodeError] if the input is invalid somehow.</span>
@ -961,6 +959,10 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x80</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x80</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x81</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x81</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x84</span><span class="p">:</span> <span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;Unexpected end-of-stream marker&#39;</span><span class="p">)</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x84</span><span class="p">:</span> <span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;Unexpected end-of-stream marker&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x85</span><span class="p">:</span>
<span class="n">a</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">unshift_annotation</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x86</span><span class="p">:</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0x86</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">decode_embedded</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">decode_embedded</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;No decode_embedded function supplied&#39;</span><span class="p">)</span> <span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;No decode_embedded function supplied&#39;</span><span class="p">)</span>
@ -981,12 +983,6 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb5</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb5</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb6</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="nb">frozenset</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb6</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="nb">frozenset</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb7</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="n">ImmutableDict</span><span class="o">.</span><span class="n">from_kvs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span> <span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xb7</span><span class="p">:</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">wrap</span><span class="p">(</span><span class="n">ImmutableDict</span><span class="o">.</span><span class="n">from_kvs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()))</span>
<span class="k">if</span> <span class="n">tag</span> <span class="o">==</span> <span class="mh">0xbf</span><span class="p">:</span>
<span class="n">vs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nextvalues</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">vs</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span> <span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;Too few items in encoded annotated value&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">include_annotations</span><span class="p">:</span>
<span class="n">vs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">annotations</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">vs</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
<span class="k">return</span> <span class="n">vs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;Invalid tag: &#39;</span> <span class="o">+</span> <span class="nb">hex</span><span class="p">(</span><span class="n">tag</span><span class="p">))</span> <span class="k">raise</span> <span class="n">DecodeError</span><span class="p">(</span><span class="s1">&#39;Invalid tag: &#39;</span> <span class="o">+</span> <span class="nb">hex</span><span class="p">(</span><span class="n">tag</span><span class="p">))</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
</details> </details>
@ -1011,15 +1007,15 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">222</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">225</span>
<span class="normal">223</span>
<span class="normal">224</span>
<span class="normal">225</span>
<span class="normal">226</span> <span class="normal">226</span>
<span class="normal">227</span> <span class="normal">227</span>
<span class="normal">228</span> <span class="normal">228</span>
<span class="normal">229</span> <span class="normal">229</span>
<span class="normal">230</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">try_next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="normal">230</span>
<span class="normal">231</span>
<span class="normal">232</span>
<span class="normal">233</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">try_next</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Like [next][preserves.binary.Decoder.next], but returns `None` instead of raising</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Like [next][preserves.binary.Decoder.next], but returns `None` instead of raising</span>
<span class="sd"> [ShortPacket][preserves.error.ShortPacket].&quot;&quot;&quot;</span> <span class="sd"> [ShortPacket][preserves.error.ShortPacket].&quot;&quot;&quot;</span>
<span class="n">start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="n">start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span>
@ -1063,7 +1059,7 @@ bytes from the front of <code>self.packet</code> and resetting <code>self.index<
<span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;hello&#39;</span><span class="p">)</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;hello&#39;</span><span class="p">)</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">annotate</span><span class="p">([],</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)))</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">annotate</span><span class="p">([],</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)))</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">contents</span><span class="p">()</span> <span class="o">&gt;&gt;&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">contents</span><span class="p">()</span>
<span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\xbf\xb5\x84\xb3\x01</span><span class="s1">x</span><span class="se">\x84</span><span class="s1">&#39;</span> <span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xb0\x01</span><span class="s1">{</span><span class="se">\xb1\x05</span><span class="s1">hello</span><span class="se">\x85\xb3\x01</span><span class="s1">x</span><span class="se">\xb5\x84</span><span class="s1">&#39;</span>
</code></pre></div> </code></pre></div>
<p><strong>Parameters:</strong></p> <p><strong>Parameters:</strong></p>
@ -1140,10 +1136,7 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">292</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">295</span>
<span class="normal">293</span>
<span class="normal">294</span>
<span class="normal">295</span>
<span class="normal">296</span> <span class="normal">296</span>
<span class="normal">297</span> <span class="normal">297</span>
<span class="normal">298</span> <span class="normal">298</span>
@ -1151,7 +1144,10 @@ annotations</a>. If explicitly <code>True</code> or
<span class="normal">300</span> <span class="normal">300</span>
<span class="normal">301</span> <span class="normal">301</span>
<span class="normal">302</span> <span class="normal">302</span>
<span class="normal">303</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="normal">303</span>
<span class="normal">304</span>
<span class="normal">305</span>
<span class="normal">306</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">encode_embedded</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span> <span class="n">encode_embedded</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span>
<span class="n">canonicalize</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">canonicalize</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">include_annotations</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="n">include_annotations</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
@ -1194,10 +1190,7 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">365</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">368</span>
<span class="normal">366</span>
<span class="normal">367</span>
<span class="normal">368</span>
<span class="normal">369</span> <span class="normal">369</span>
<span class="normal">370</span> <span class="normal">370</span>
<span class="normal">371</span> <span class="normal">371</span>
@ -1231,7 +1224,10 @@ annotations</a>. If explicitly <code>True</code> or
<span class="normal">399</span> <span class="normal">399</span>
<span class="normal">400</span> <span class="normal">400</span>
<span class="normal">401</span> <span class="normal">401</span>
<span class="normal">402</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span> <span class="normal">402</span>
<span class="normal">403</span>
<span class="normal">404</span>
<span class="normal">405</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Extend `self.buffer` with an encoding of `v`.&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Extend `self.buffer` with an encoding of `v`.&quot;&quot;&quot;</span>
<span class="n">v</span> <span class="o">=</span> <span class="n">preserve</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="n">v</span> <span class="o">=</span> <span class="n">preserve</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="s1">&#39;__preserve_write_binary__&#39;</span><span class="p">):</span> <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="s1">&#39;__preserve_write_binary__&#39;</span><span class="p">):</span>
@ -1291,9 +1287,9 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">314</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">317</span>
<span class="normal">315</span> <span class="normal">318</span>
<span class="normal">316</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">contents</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="normal">319</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">contents</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns a `bytes` constructed from the contents of `self.buffer`.&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Returns a `bytes` constructed from the contents of `self.buffer`.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buffer</span><span class="p">)</span> <span class="k">return</span> <span class="nb">bytes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buffer</span><span class="p">)</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
@ -1318,9 +1314,9 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">305</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">308</span>
<span class="normal">306</span> <span class="normal">309</span>
<span class="normal">307</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="normal">310</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Clears `self.buffer` to a fresh empty `bytearray`.&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Clears `self.buffer` to a fresh empty `bytearray`.&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">buffer</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">buffer</span> <span class="o">=</span> <span class="nb">bytearray</span><span class="p">()</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
@ -1355,12 +1351,12 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">430</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">433</span>
<span class="normal">431</span>
<span class="normal">432</span>
<span class="normal">433</span>
<span class="normal">434</span> <span class="normal">434</span>
<span class="normal">435</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">canonicalize</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="normal">435</span>
<span class="normal">436</span>
<span class="normal">437</span>
<span class="normal">438</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">canonicalize</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;As [encode][preserves.binary.encode], but sets `canonicalize=True` in the</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;As [encode][preserves.binary.encode], but sets `canonicalize=True` in the</span>
<span class="sd"> [Encoder][preserves.binary.Encoder] constructor.</span> <span class="sd"> [Encoder][preserves.binary.Encoder] constructor.</span>
@ -1414,16 +1410,16 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">241</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">244</span>
<span class="normal">242</span>
<span class="normal">243</span>
<span class="normal">244</span>
<span class="normal">245</span> <span class="normal">245</span>
<span class="normal">246</span> <span class="normal">246</span>
<span class="normal">247</span> <span class="normal">247</span>
<span class="normal">248</span> <span class="normal">248</span>
<span class="normal">249</span> <span class="normal">249</span>
<span class="normal">250</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="n">bs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="normal">250</span>
<span class="normal">251</span>
<span class="normal">252</span>
<span class="normal">253</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">decode</span><span class="p">(</span><span class="n">bs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Yields the first complete encoded value from `bs`, passing `kwargs` through to the</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Yields the first complete encoded value from `bs`, passing `kwargs` through to the</span>
<span class="sd"> [Decoder][preserves.binary.Decoder] constructor. Raises exceptions as per</span> <span class="sd"> [Decoder][preserves.binary.Decoder] constructor. Raises exceptions as per</span>
<span class="sd"> [next][preserves.binary.Decoder.next].</span> <span class="sd"> [next][preserves.binary.Decoder.next].</span>
@ -1456,10 +1452,10 @@ annotations</a>. If explicitly <code>True</code> or
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">252</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">255</span>
<span class="normal">253</span> <span class="normal">256</span>
<span class="normal">254</span> <span class="normal">257</span>
<span class="normal">255</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">decode_with_annotations</span><span class="p">(</span><span class="n">bs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="normal">258</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">decode_with_annotations</span><span class="p">(</span><span class="n">bs</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Like [decode][preserves.binary.decode], but supplying `include_annotations=True` to the</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Like [decode][preserves.binary.decode], but supplying `include_annotations=True` to the</span>
<span class="sd"> [Decoder][preserves.binary.Decoder] constructor.&quot;&quot;&quot;</span> <span class="sd"> [Decoder][preserves.binary.Decoder] constructor.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Decoder</span><span class="p">(</span><span class="n">packet</span><span class="o">=</span><span class="n">bs</span><span class="p">,</span> <span class="n">include_annotations</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> <span class="k">return</span> <span class="n">Decoder</span><span class="p">(</span><span class="n">packet</span><span class="o">=</span><span class="n">bs</span><span class="p">,</span> <span class="n">include_annotations</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
@ -1486,12 +1482,12 @@ underlying <a class="autorefs autorefs-internal" href="#preserves.binary.Encoder
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/binary.py</code></summary> <summary>Source code in <code>preserves/binary.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">423</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">426</span>
<span class="normal">424</span>
<span class="normal">425</span>
<span class="normal">426</span>
<span class="normal">427</span> <span class="normal">427</span>
<span class="normal">428</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">encode</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <span class="normal">428</span>
<span class="normal">429</span>
<span class="normal">430</span>
<span class="normal">431</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">encode</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Encode a single `Value` `v` to a byte string. Any supplied `kwargs` are passed on to the</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Encode a single `Value` `v` to a byte string. Any supplied `kwargs` are passed on to the</span>
<span class="sd"> underlying [Encoder][preserves.binary.Encoder] constructor.&quot;&quot;&quot;</span> <span class="sd"> underlying [Encoder][preserves.binary.Encoder] constructor.&quot;&quot;&quot;</span>
<span class="n">e</span> <span class="o">=</span> <span class="n">Encoder</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="n">e</span> <span class="o">=</span> <span class="n">Encoder</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

View File

@ -731,8 +731,8 @@ annotations (for documentation and other purposes).</p>
<span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLMHZGlzY2FyZLMIc3VycHJpc2WE] &lt;discard surprise&gt;&gt;</span> <span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLMHZGlzY2FyZLMIc3VycHJpc2WE] &lt;discard surprise&gt;&gt;</span>
<span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLEHYVN0cmluZ7ABA7ABBIQ=] &lt;&quot;aString&quot; 3 4&gt;&gt;</span> <span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLEHYVN0cmluZ7ABA7ABBIQ=] &lt;&quot;aString&quot; 3 4&gt;&gt;</span>
<span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLSzB2Rpc2NhcmSEsAEDsAEEhA==] &lt;&lt;discard&gt; 3 4&gt;&gt;</span> <span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tLSzB2Rpc2NhcmSEsAEDsAEEhA==] &lt;&lt;discard&gt; 3 4&gt;&gt;</span>
<span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[v7SzAVK/swFmswJhZoSEswJhcoQ=] @ar &lt;R @af f&gt;&gt;</span> <span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[hbMCYXK0swFShbMCYWazAWaE] @ar &lt;R @af f&gt;&gt;</span>
<span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tL+zAVKzAmFyhL+zAWazAmFmhIQ=] &lt;@ar R @af f&gt;&gt;</span> <span class="o">&lt;</span><span class="n">Test</span> <span class="c1">#[tIWzAmFyswFShbMCYWazAWaE] &lt;@ar R @af f&gt;&gt;</span>
</code></pre></div> </code></pre></div>

File diff suppressed because one or more lines are too long

View File

@ -2,57 +2,57 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://preserves.dev/python/latest/</loc> <loc>https://preserves.dev/python/latest/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/api/</loc> <loc>https://preserves.dev/python/latest/api/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/binary/</loc> <loc>https://preserves.dev/python/latest/binary/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/compare/</loc> <loc>https://preserves.dev/python/latest/compare/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/error/</loc> <loc>https://preserves.dev/python/latest/error/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/fold/</loc> <loc>https://preserves.dev/python/latest/fold/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/merge/</loc> <loc>https://preserves.dev/python/latest/merge/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/path/</loc> <loc>https://preserves.dev/python/latest/path/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/schema/</loc> <loc>https://preserves.dev/python/latest/schema/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/text/</loc> <loc>https://preserves.dev/python/latest/text/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://preserves.dev/python/latest/values/</loc> <loc>https://preserves.dev/python/latest/values/</loc>
<lastmod>2023-10-13</lastmod> <lastmod>2023-10-14</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
</urlset> </urlset>

View File

@ -940,9 +940,9 @@ about annotations</a>.</p>
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">602</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">599</span>
<span class="normal">603</span> <span class="normal">600</span>
<span class="normal">604</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">peel</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="normal">601</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">peel</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Calls [strip_annotations][preserves.values.strip_annotations] on `self` with `depth=1`.&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Calls [strip_annotations][preserves.values.strip_annotations] on `self` with `depth=1`.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">strip_annotations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="n">strip_annotations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
@ -967,9 +967,9 @@ about annotations</a>.</p>
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">598</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">595</span>
<span class="normal">599</span> <span class="normal">596</span>
<span class="normal">600</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">strip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">inf</span><span class="p">):</span> <span class="normal">597</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">strip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">inf</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Calls [strip_annotations][preserves.values.strip_annotations] on `self` and `depth`.&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Calls [strip_annotations][preserves.values.strip_annotations] on `self` and `depth`.&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">strip_annotations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="p">)</span> <span class="k">return</span> <span class="n">strip_annotations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">depth</span><span class="p">)</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
@ -1040,8 +1040,8 @@ Preserves <code>Value</code>, could be <code>None</code>, could be anything!</p>
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">724</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">721</span>
<span class="normal">725</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">embeddedValue</span><span class="p">):</span> <span class="normal">722</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">embeddedValue</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">embeddedValue</span> <span class="o">=</span> <span class="n">embeddedValue</span> <span class="bp">self</span><span class="o">.</span><span class="n">embeddedValue</span> <span class="o">=</span> <span class="n">embeddedValue</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
</details> </details>
@ -2143,7 +2143,10 @@ wrapped, and appends each of the <code>anns</code> to the <a class="autorefs aut
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">668</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">665</span>
<span class="normal">666</span>
<span class="normal">667</span>
<span class="normal">668</span>
<span class="normal">669</span> <span class="normal">669</span>
<span class="normal">670</span> <span class="normal">670</span>
<span class="normal">671</span> <span class="normal">671</span>
@ -2157,10 +2160,7 @@ wrapped, and appends each of the <code>anns</code> to the <a class="autorefs aut
<span class="normal">679</span> <span class="normal">679</span>
<span class="normal">680</span> <span class="normal">680</span>
<span class="normal">681</span> <span class="normal">681</span>
<span class="normal">682</span> <span class="normal">682</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">annotate</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">*</span><span class="n">anns</span><span class="p">):</span>
<span class="normal">683</span>
<span class="normal">684</span>
<span class="normal">685</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">annotate</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="o">*</span><span class="n">anns</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Wraps `v` in an [Annotated][preserves.values.Annotated] object, if it isn&#39;t already</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Wraps `v` in an [Annotated][preserves.values.Annotated] object, if it isn&#39;t already</span>
<span class="sd"> wrapped, and appends each of the `anns` to the [Annotated][preserves.values.Annotated]&#39;s</span> <span class="sd"> wrapped, and appends each of the `anns` to the [Annotated][preserves.values.Annotated]&#39;s</span>
<span class="sd"> `annotations` sequence. NOTE: Does not recursively ensure that any parts of the argument</span> <span class="sd"> `annotations` sequence. NOTE: Does not recursively ensure that any parts of the argument</span>
@ -2293,9 +2293,9 @@ sense the inverse of <a class="autorefs autorefs-internal" href="#preserves.valu
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">618</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">615</span>
<span class="normal">619</span> <span class="normal">616</span>
<span class="normal">620</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">is_annotated</span><span class="p">(</span><span class="n">v</span><span class="p">):</span> <span class="normal">617</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">is_annotated</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;`True` iff `v` is an instance of [Annotated][preserves.values.Annotated].&quot;&quot;&quot;</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;`True` iff `v` is an instance of [Annotated][preserves.values.Annotated].&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">Annotated</span><span class="p">)</span> <span class="k">return</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">Annotated</span><span class="p">)</span>
</code></pre></div></td></tr></table></div> </code></pre></div></td></tr></table></div>
@ -2387,7 +2387,10 @@ into the structure of <code>v.item</code>.</p>
<details class="quote"> <details class="quote">
<summary>Source code in <code>preserves/values.py</code></summary> <summary>Source code in <code>preserves/values.py</code></summary>
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">622</span> <div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">619</span>
<span class="normal">620</span>
<span class="normal">621</span>
<span class="normal">622</span>
<span class="normal">623</span> <span class="normal">623</span>
<span class="normal">624</span> <span class="normal">624</span>
<span class="normal">625</span> <span class="normal">625</span>
@ -2428,10 +2431,7 @@ into the structure of <code>v.item</code>.</p>
<span class="normal">660</span> <span class="normal">660</span>
<span class="normal">661</span> <span class="normal">661</span>
<span class="normal">662</span> <span class="normal">662</span>
<span class="normal">663</span> <span class="normal">663</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">strip_annotations</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">inf</span><span class="p">):</span>
<span class="normal">664</span>
<span class="normal">665</span>
<span class="normal">666</span></pre></div></td><td class="code"><div><pre><span></span><code><span class="k">def</span> <span class="nf">strip_annotations</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">depth</span><span class="o">=</span><span class="n">inf</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Exposes `depth` layers of raw structure of</span> <span class="w"> </span><span class="sd">&quot;&quot;&quot;Exposes `depth` layers of raw structure of</span>
<span class="sd"> potentially-[Annotated][preserves.values.Annotated] `Value`s. If `depth==0` or `v` is not</span> <span class="sd"> potentially-[Annotated][preserves.values.Annotated] `Value`s. If `depth==0` or `v` is not</span>
<span class="sd"> [Annotated][preserves.values.Annotated], just returns `v`. Otherwise, descends recursively</span> <span class="sd"> [Annotated][preserves.values.Annotated], just returns `v`. Otherwise, descends recursively</span>

Binary file not shown.

View File

@ -43,17 +43,17 @@
"13/14 and 16/17, depending on how they wish to treat end-of-stream conditions." "13/14 and 16/17, depending on how they wish to treat end-of-stream conditions."
]> ]>
<TestCases { <TestCases {
annotation1: <Test #x"BFB00109B10361626384" @"abc" 9> annotation1: <Test #x"85 B103616263 B00109" @"abc" 9>
annotation2: <Test #x"BF B5 B584 BF B584 B10178 84 84 B103616263 B103646566 84" @"abc" @"def" [[] @"x" []]> annotation2: <Test #x"85 B103616263 85 B103646566 B5 B584 85 B10178 B584 84" @"abc" @"def" [[] @"x" []]>
annotation3: <Test #x"BF B00105 BF B00102 B00101 84 BF B00104 B00103 84 84" @@1 2 @@3 4 5> annotation3: <Test #x"85 85 B00101 B00102 85 85 B00103 B00104 B00105" @@1 2 @@3 4 5>
annotation4: <NondeterministicTest annotation4: <NondeterministicTest
#x"B7 BF B30161 B302616b 84 BF B00101 B3026176 84 BF B30162 B302626b 84 BF B00102 B3026276 84 84" #x"B7 85 B302616b B30161 85 B3026176 B00101 85 B302626b B30162 85 B3026276 B00102 84"
{@ak a: @av 1 @bk b: @bv 2}> {@ak a: @av 1 @bk b: @bv 2}>
annotation5: <Test #x"BF B4 B30152 BF B30166 B3026166 84 84 B3026172 84" @ar <R @af f>> annotation5: <Test #x"85 B3026172 B4 B30152 85 B3026166 B30166 84" @ar <R @af f>>
annotation6: <Test #x"B4 BF B30152 B3026172 84 BF B30166 B3026166 84 84" <@ar R @af f>> annotation6: <Test #x"B4 85 B3026172 B30152 85 B3026166 B30166 84" <@ar R @af f>>
annotation7: annotation7:
;Stop reading symbols at @ -- this test has three separate annotations ;Stop reading symbols at @ -- this test has three separate annotations
<Test #x"BF B584 B30161 B30162 B30163 84" @a@b@c[]> <Test #x"85 B30161 85 B30162 85 B30163 B584" @a@b@c[]>
bytes2: <Test #x"B20568656c6c6f" #"hello"> bytes2: <Test #x"B20568656c6c6f" #"hello">
bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello"> bytes2a: <Test @"Internal whitespace is allowed, including commas!" #x"B2, 05, 68, 65, 6c, 6c, 6f" #"hello">
bytes3: <Test #x"B203414243" #"ABC"> bytes3: <Test #x"B203414243" #"ABC">