@@ -14,46 +14,25 @@ struct Body(Copyable, Movable, Sized):
1414 self .body = List[Byte](body)
1515 self ._json_cache = None
1616
17- fn __init__ (out self , var body : List[Byte]):
18- self .body = body^
19- self ._json_cache = None
20-
21- fn __init__ (out self ):
22- self .body = List[Byte]()
23- self ._json_cache = None
24-
25- fn __init__ (out self , var data : emberjson.Object):
26- """ Initializes the body from a dictionary, converting it to a form-encoded string."""
27- self .body = List[Byte](emberjson.to_string(data^ ).as_bytes())
28- self ._json_cache = None
29-
3017 fn __len__ (self ) -> Int:
3118 return len (self .body)
3219
33- fn __iadd__ (mut self , var other : Body):
34- self .body += other.body^
35- other.body = List[Byte]()
36-
37- fn __iadd__ (mut self , other : Span[Byte]):
38- self .body.extend(other)
39-
4020 fn as_bytes (self ) -> Span[Byte, origin_of(self .body)]:
4121 return Span(self .body)
4222
4323 fn as_string_slice (self ) -> StringSlice[origin_of(self .body)]:
4424 return StringSlice(unsafe_from_utf8 = Span(self .body))
4525
46- fn as_json (mut self ) raises -> ref [origin_of(self ._json_cache.value()._data) ] emberjson.Object :
26+ fn as_json (mut self ) raises -> ref [origin_of(self ._json_cache._value) ] emberjson.JSON :
4727 """ Converts the response body to a JSON object."""
4828 if not self .body:
4929 raise Error(" Body is empty; cannot parse as JSON." )
5030
5131 if self ._json_cache:
52- return self ._json_cache.value().object()
32+ return self ._json_cache.value()
5333
54- var parser = emberjson.Parser(StringSlice(unsafe_from_utf8 = self .body))
55- self ._json_cache = parser.parse()
56- return self ._json_cache.value().object()
34+ self ._json_cache = emberjson.parse(StringSlice(unsafe_from_utf8 = self .body))
35+ return self ._json_cache.value()
5736
5837 fn write_to [W : Writer, //](self , mut writer : W):
5938 """ Writes the body to a writer.
0 commit comments