protosphere
Version:
protocol buffers made easy
79 lines (69 loc) • 2.15 kB
HTML
<script src="/helpers/axios.min.js"></script>
<script src="/dist/protosphere.min.js"></script>
<script>
const ps = new Protosphere({
name: Protosphere.String(),
details: Protosphere.Object({
verified: Protosphere.Boolean()
}),
age: Protosphere.Integer(),
bitcoins: Protosphere.Double(),
memberships: Protosphere.Array(
Protosphere.String()
),
coinPairs: Protosphere.Array(
Protosphere.Array(
Protosphere.String()
)
),
configs: Protosphere.Object({
video: Protosphere.Object({
hue: Protosphere.Integer(),
saturation: Protosphere.Integer()
}),
audio: Protosphere.Object({
volume: Protosphere.Double()
})
}),
undefinedBoolean: Protosphere.Boolean(),
nullBoolean: Protosphere.Boolean(),
errorBoolean: Protosphere.Boolean(),
undefinedString: Protosphere.String(),
nullString: Protosphere.String(),
errorString: Protosphere.String(),
undefinedInteger: Protosphere.Integer(),
nullInteger: Protosphere.Integer(),
errorInteger: Protosphere.Integer(),
undefinedDouble: Protosphere.Double(),
nullDouble: Protosphere.Double(),
errorDouble: Protosphere.Double(),
undefinedArray: Protosphere.Array(),
nullArray: Protosphere.Array(),
errorArray: Protosphere.Array(),
undefinedObject: Protosphere.Object(),
nullObject: Protosphere.Object(),
errorObject: Protosphere.Object(),
});
axios({
method:'get',
url:'/endpoint/json',
responseType:'json'
})
.then((response) =>console.log('json', response.data))
.catch(console.error);
axios({
method:'get',
url:'/endpoint/arraybuffer_raw',
responseType:'arraybuffer'
})
.then((response) =>console.log('raw', response.data))
.catch(console.error);
axios({
method:'get',
url:'/endpoint/arraybuffer_protosphere',
responseType:'arraybuffer'
})
.then((response) => ps.hydrate(response.data))
.then((result) => console.log('arraybuffer', result))
.catch(console.error);
</script>