speice.io/assets/js/ef7aa1ca.f98a4c92.js

1 line
18 KiB
JavaScript
Raw Permalink Normal View History

"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["832"],{8603:function(e,t,n){n.r(t),n.d(t,{assets:function(){return c},contentTitle:function(){return r},default:function(){return d},frontMatter:function(){return s},metadata:function(){return o},toc:function(){return l}});var o=n(457),a=n(5893),i=n(65);let s={slug:"2018/01/captains-cookbook-part-1",title:"Captain's Cookbook: Project setup",date:new Date("2018-01-16T12:00:00.000Z"),authors:["bspeice"],tags:[]},r=void 0,c={authorsImageUrls:[void 0]},l=[{value:"Step 1: Installing <code>capnp</code>",id:"step-1-installing-capnp",level:2},{value:"Step 2: Starting a Cap&#39;N Proto Rust project",id:"step-2-starting-a-capn-proto-rust-project",level:2},{value:"Step 3: Writing a basic schema",id:"step-3-writing-a-basic-schema",level:2},{value:"Step 4: Setting up the build process",id:"step-4-setting-up-the-build-process",level:2},{value:"Step 5: Running the build",id:"step-5-running-the-build",level:2},{value:"Step 6: Making a point",id:"step-6-making-a-point",level:2}];function p(e){let t={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",ul:"ul",...(0,i.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.p,{children:"A basic introduction to getting started with Cap'N Proto."}),"\n",(0,a.jsxs)(t.p,{children:["I've been working a lot with ",(0,a.jsx)(t.a,{href:"https://capnproto.org/",children:"Cap'N Proto"})," recently with Rust, but there's a real dearth of information\non how to set up and get going quickly. In the interest of trying to get more people using this (because I think it's\nfantastic), I'm going to work through a couple of examples detailing what exactly should be done to get going."]}),"\n",(0,a.jsxs)(t.p,{children:["So, what is Cap'N Proto? It's a data serialization library. It has contemporaries with ",(0,a.jsx)(t.a,{href:"https://developers.google.com/protocol-buffers/",children:"Protobuf"}),"\nand ",(0,a.jsx)(t.a,{href:"https://google.github.io/flatbuffers/",children:"FlatBuffers"}),", but is better compared with FlatBuffers. The whole point behind it\nis to define a schema language and serialization format such that:"]}),"\n",(0,a.jsxs)(t.ol,{children:["\n",(0,a.jsx)(t.li,{children:"Applications that do not share the same base programming language can communicate"}),"\n",(0,a.jsx)(t.li,{children:"The data and schema you use can naturally evolve over time as your needs change"}),"\n"]}),"\n",(0,a.jsx)(t.p,{children:"Accompanying this are typically code generators that take the schemas you define for your application and give you back\ncode for different languages to get data to and from that schema."}),"\n",(0,a.jsx)(t.p,{children:"Now, what makes Cap'N Proto different from, say, Protobuf, is that there is no serialization/deserialization step the same way\nas is implemented with Protobuf. Instead, the idea is that the message itself can be loaded in memory and used directly there."}),"\n",(0,a.jsxs)(t.p,{children:["We're going to take a look at a series of progressively more complex projects that use Cap'N Proto in an effort to provide some\nexamples of what idiomatic usage looks like, and shorten the startup time needed to make use of this library in Rust projects.\nIf you want to follow along, feel free. If not, I've posted ",(0,a.jsx)(t.a,{href:"https://github.com/bspeice/capnp_cookbook_1",children:"the final result"}),"\nfor reference."]}),"\n",(0,a.jsxs)(t.h2,{id:"step-1-installing-capnp",children:["Step 1: Installing ",(0,a.jsx)(t.code,{children:"capnp"})]}),"\n",(0,a.jsxs)(t.p,{children:["The ",(0,a.jsx)(t.code,{children:"capnp"})," binary itself is needed for taking the schema files you write and turning them into a format that can be used by the\ncode generation libraries. Don't ask me what that actually means, I just know that you need to make sure this is installed."]}),"\n",(0,a.jsxs)(t.p,{children:["I'll refer you to ",(0,a.jsx)(t.a,{href:"https://capnproto.org/install.html",children:"Cap'N Proto's installation instructions"})," here. As a quick TLDR though:"]}),"\n",(0,a.jsxs)(t.ul,{ch