Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
URLCachedResponse Struct Reference

#include <URLCachedResponse.h>

Overview

A cached HTTP response.

Definition at line 44 of file URLCachedResponse.h.

Inheritance diagram for URLCachedResponse:
Object

Properties

Datadata
 The response body.
 
Object object
 The superclass.
 
URLResponseresponse
 The HTTP response.
 
size_t size
 The cached body size.
 
Datetimestamp
 The time this response was cached.
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class.
 
unsigned int magic
 A header to allow introspection of Object types.
 

Methods

Class_URLCachedResponse (void)
 The URLCachedResponse archetype.
 
URLCachedResponseinitWithResponseData (URLCachedResponse *self, const URLResponse *response, const Data *data)
 Initializes this URLCachedResponse with the given response and data.
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype.
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object.
 
void dealloc (Object *self)
 Frees all resources held by this Object.
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object.
 
bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object.
 
bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership.
 

Protected Attributes

URLCachedResponseInterface * interface
 The interface.
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface.
 

Property Details

◆ data

Data* URLCachedResponse::data

The response body.

Definition at line 65 of file URLCachedResponse.h.

◆ interface

URLCachedResponseInterface* URLCachedResponse::interface
protected

The interface.

Definition at line 55 of file URLCachedResponse.h.

◆ object

Object URLCachedResponse::object

The superclass.

Definition at line 49 of file URLCachedResponse.h.

◆ response

URLResponse* URLCachedResponse::response

The HTTP response.

Definition at line 60 of file URLCachedResponse.h.

◆ size

size_t URLCachedResponse::size

The cached body size.

Definition at line 75 of file URLCachedResponse.h.

◆ timestamp

Date* URLCachedResponse::timestamp

The time this response was cached.

Definition at line 70 of file URLCachedResponse.h.

Method Details

◆ _URLCachedResponse()

Class * _URLCachedResponse ( void  )

The URLCachedResponse archetype.

Returns
The URLCachedResponse Class.

Definition at line 164 of file URLCachedResponse.c.

164 {
165 static Class *clazz;
166 static Once once;
167
168 do_once(&once, {
169 clazz = _initialize(&(const ClassDef) {
170 .name = "URLCachedResponse",
171 .superclass = _Object(),
172 .instanceSize = sizeof(URLCachedResponse),
173 .interfaceOffset = offsetof(URLCachedResponse, interface),
174 .interfaceSize = sizeof(URLCachedResponseInterface),
176 });
177 });
178
179 return clazz;
180}
static void initialize(Class *clazz)
Definition Array.c:710
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
long Once
The Once type.
Definition Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition Class.h:41
The runtime representation of a Class.
Definition Class.h:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition Object.h:55
Class * _Object(void)
The Object archetype.
Definition Object.c:136
A cached HTTP response.
URLCachedResponseInterface * interface
The interface.

◆ initWithResponseData()

URLCachedResponse * initWithResponseData ( URLCachedResponse self,
const URLResponse response,
const Data data 
)

Initializes this URLCachedResponse with the given response and data.

Parameters
selfThe URLCachedResponse.
responseThe HTTP response.
dataThe response body.
Returns
The initialized URLCachedResponse, or NULL on error.

Definition at line 123 of file URLCachedResponse.c.

124 {
125
126 assert(response);
127
128 self = (URLCachedResponse *) super(Object, self, init);
129 if (self) {
130 self->response = (URLResponse *) $((Object *) response, copy);
131
132 if (data) {
133 self->data = $(alloc(Data), initWithBytes, data->bytes, data->length);
134 } else {
135 self->data = $(alloc(Data), initWithBytes, (const uint8_t *) "", 0);
136 }
137
138 self->timestamp = $$(Date, date);
139 self->size = self->data ? self->data->length : 0;
140 }
141
142 return self;
143}
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:176
#define super(type, obj, method,...)
static Data * initWithBytes(Data *self, const uint8_t *bytes, size_t length)
Definition Data.c:151
static Date * date(void)
Definition Date.c:98
Data buffers.
Definition Data.h:50
size_t length
The length of bytes.
Definition Data.h:76
uint8_t * bytes
The bytes.
Definition Data.h:66
Microsecond-precision immutable dates.
Definition Date.h:74
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition Object.c:83
Object * copy(const Object *self)
Creates a shallow copy of this Object.
Definition Array.c:84
URLResponse * response
The HTTP response.
Data * data
The response body.
Date * timestamp
The time this response was cached.
size_t size
The cached body size.
A protocol-agnostic abstraction for URLSessionTask responses.
Definition URLResponse.h:42

The documentation for this struct was generated from the following files: