OverviewFilesCommitsIssuesDocsReleasesPeers

holepunchto-deps / @holepunchto / keet-room-registry / spec / hyperdb / messages.js

1 lines · javascript ref:
const{c:e}=require("hyperschema/runtime");let n=1;const t={preencode(n,t){e.buffer.preencode(n,t.inlined),n.end++,t.name&&e.string.preencode(n,t.name),t.mimetype&&e.string.preencode(n,t.mimetype),t.hash&&e.fixed32.preencode(n,t.hash),t.width&&e.uint.preencode(n,t.width),t.height&&e.uint.preencode(n,t.height)},encode(n,t){const i=(t.name?1:0)|(t.mimetype?2:0)|(t.hash?4:0)|(t.width?8:0)|(t.height?16:0);e.buffer.encode(n,t.inlined),e.uint.encode(n,i),t.name&&e.string.encode(n,t.name),t.mimetype&&e.string.encode(n,t.mimetype),t.hash&&e.fixed32.encode(n,t.hash),t.width&&e.uint.encode(n,t.width),t.height&&e.uint.encode(n,t.height)},decode(n){const t=e.buffer.decode(n),i=e.uint.decode(n);return{inlined:t,name:1&i?e.string.decode(n):null,mimetype:2&i?e.string.decode(n):null,hash:4&i?e.fixed32.decode(n):null,width:8&i?e.uint.decode(n):0,height:16&i?e.uint.decode(n):0}}},i=e.frame(t),o={preencode(n,t){e.fixed32.preencode(n,t.roomKey),n.end++,t.title&&e.string.preencode(n,t.title),t.avatar&&i.preencode(n,t.avatar),t.invitation&&e.buffer.preencode(n,t.invitation)},encode(n,t){const o=(t.title?1:0)|(t.avatar?2:0)|(t.invitation?4:0)|(t.verified?8:0);e.fixed32.encode(n,t.roomKey),e.uint.encode(n,o),t.title&&e.string.encode(n,t.title),t.avatar&&i.encode(n,t.avatar),t.invitation&&e.buffer.encode(n,t.invitation)},decode(n){const t=e.fixed32.decode(n),o=e.uint.decode(n);return{roomKey:t,title:1&o?e.string.decode(n):null,avatar:2&o?i.decode(n):null,invitation:4&o?e.buffer.decode(n):null,verified:!!(8&o)}}},d=i,r={preencode(n,t){n.end++,t.title&&e.string.preencode(n,t.title),t.avatar&&d.preencode(n,t.avatar),t.invitation&&e.buffer.preencode(n,t.invitation)},encode(n,t){const i=(t.title?1:0)|(t.avatar?2:0)|(t.invitation?4:0)|(t.verified?8:0);e.uint.encode(n,i),t.title&&e.string.encode(n,t.title),t.avatar&&d.encode(n,t.avatar),t.invitation&&e.buffer.encode(n,t.invitation)},decode(n){const t=e.uint.decode(n);return{roomKey:null,title:1&t?e.string.decode(n):null,avatar:2&t?d.decode(n):null,invitation:4&t?e.buffer.decode(n):null,verified:!!(8&t)}}};function c(e){switch(e){case"@keet-room-registry/avatar":return t;case"@keet-room-registry/room":return o;case"@keet-room-registry/room/hyperdb#0":return r;default:throw new Error("Encoder not found "+e)}}function a(e,t=1){const i=c(e);return{preencode(e,o){n=t,i.preencode(e,o)},encode(e,o){n=t,i.encode(e,o)},decode:e=>(n=t,i.decode(e))}}const u=a;module.exports={resolveStruct:u,getStruct:a,getEnum:function(e){throw new Error("Enum not found "+e)},getEncoding:c,encode:function(t,i,o=1){return n=o,e.encode(c(t),i)},decode:function(t,i,o=1){return n=o,e.decode(c(t),i)},setVersion:function(e){n=e},version:n};