OverviewFilesCommitsIssuesDocsReleasesPeers

holepunchto-deps / @holepunchto / keet-core-schemas / lib / members / messages.js

1 lines · javascript ref:
const e=require("@holepunchto/hyperindex"),d=require("compact-encoding"),i=d.fixed32,t=d.buffer,n=d.array(d.fixed32),c=e.BUFFER,o={preencode(e,i){d.fixed32.preencode(e,i.memberKey),d.buffer.preencode(e,i.proof)},encode(e,i){d.fixed32.encode(e,i.memberKey),d.buffer.encode(e,i.proof)},decode:e=>({memberKey:d.fixed32.decode(e),proof:d.buffer.decode(e)})},a={preencode(e,i){e.end++,d.fixed32.preencode(e,i.key),i.displayName&&d.string.preencode(e,i.displayName),i.capabilities&&d.uint.preencode(e,i.capabilities)},encode(e,i){const t=e.start++;d.fixed32.encode(e,i.key);let n=0;i.displayName&&(n|=1,d.string.encode(e,i.displayName)),i.capabilities&&(n|=2,d.uint.encode(e,i.capabilities)),i.hasAvatar&&(n|=4),e.buffer[t]=n},decode(e){const i=d.uint.decode(e);return{key:d.fixed32.decode(e),displayName:1&i?d.string.decode(e):null,capabilities:2&i?d.uint.decode(e):0,hasAvatar:!!(4&i)}}},r={preencode(e,i){d.fixed32.preencode(e,i.memberKey),d.buffer.preencode(e,i.receipt)},encode(e,i){d.fixed32.encode(e,i.memberKey),d.buffer.encode(e,i.receipt)},decode:e=>({memberKey:d.fixed32.decode(e),receipt:d.buffer.decode(e)})},p={preencode(e,i){let t=0;i.displayName&&(t|=1),i.hasAvatar&&(t|=2),i.inactive&&(t|=4),d.uint.preencode(e,t),d.uint.preencode(e,i.timestamp),d.fixed32.preencode(e,i.key),d.uint.preencode(e,i.capabilities),d.buffer.preencode(e,i.latestReceipt),n.preencode(e,i.devices),i.displayName&&d.string.preencode(e,i.displayName),i.inactive&&n.preencode(e,i.inactive)},encode(e,i){let t=0;i.displayName&&(t|=1),i.hasAvatar&&(t|=2),i.inactive&&(t|=4),d.uint.encode(e,t),d.uint.encode(e,i.timestamp),d.fixed32.encode(e,i.key),d.uint.encode(e,i.capabilities),d.buffer.encode(e,i.latestReceipt),n.encode(e,i.devices),i.displayName&&d.string.encode(e,i.displayName),i.inactive&&n.encode(e,i.inactive)},decode(e){const i=d.uint.decode(e);return{timestamp:d.uint.decode(e),key:d.fixed32.decode(e),capabilities:d.uint.decode(e),latestReceipt:d.buffer.decode(e),devices:n.decode(e),displayName:1&i?d.string.decode(e):null,hasAvatar:!!(2&i),inactive:4&i?n.decode(e):null}}},s={preencode(e,i){e.end++,d.uint.preencode(e,i.capabilities),i.invitation&&d.fixed32.preencode(e,i.invitation),i.attestation&&r.preencode(e,i.attestation)},encode(e,i){const t=e.start++;d.uint.encode(e,i.capabilities);let n=0;i.invitation&&(n|=1,d.fixed32.encode(e,i.invitation)),i.attestation&&(n|=2,r.encode(e,i.attestation)),e.buffer[t]=n},decode(e){const i=d.uint.decode(e);return{capabilities:d.uint.decode(e),invitation:1&i?d.fixed32.decode(e):null,attestation:2&i?r.decode(e):null}}};module.exports={Identity:o,MemberId:i,IndexMemberId:c,PendingMemberRecord:s,IndexMemberRecord:a,AvatarRecord:t,MemberRecord:p};