Skip to content

Instantly share code, notes, and snippets.

The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
node_modules/dictav-flatbuffers/js/flatbuffers.js (1143:0)
1141:
1142: // Exports for Node.js and RequireJS
1143: this.flatbuffers = flatbuffers;
^
1144:
1145: /// @endcond
import npm from 'rollup-plugin-node-resolve'
import replace from 'rollup-plugin-replace'
export default {
entry: 'index.js',
moduleName: 'npmtest',
format: 'iife',
plugins: [
npm({
jsnext: true, // if provided in ES6
@dictav
dictav / package.json
Created January 5, 2017 07:30
package.json for FlatBuffers
{
"name": "dictav-flatbuffers",
"version": "1.5.0",
"description": "Memory Efficient Serialization Library",
"files": ["js/flatbuffers.js"],
"main": "js/flatbuffers.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@dictav
dictav / person.proto
Created January 10, 2017 03:43
Protocol Buffer example
syntax = "proto3";
package grpcexample;
service GRPCExample {
rpc GetPerson(Request) returns (Person) {}
rpc ListPeople(Request) returns (stream Person) {}
}
message Request {
@dictav
dictav / hello.fbs
Created January 10, 2017 03:54
FlatBuffer IDL example
namespace hello;
table Message {
name: string;
text: string;
}
rpc_service Greeter {
Hello(Message): Message;
}
@dictav
dictav / person.fbs
Last active January 16, 2017 13:09
namespace grpcexample;
rpc_service GRPCExample {
GetPerson(Request): Person;
ListPeople(Request): Person (streaming: "server");
ArrayPeople(Request): Result;
}
enum PhoneType: byte {
MOBILE,

Protocol Buffers の結果

make test
go test -tags=server -benchmem -bench .
BenchmarkGetPerson-4    	   10000	    195872 ns/op	    6526 B/op	     116 allocs/op
BenchmarkListPerson-4   	    2000	    774706 ns/op	   80248 B/op	    1580 allocs/op
PASS
ok  	github.com/dictav/test-go-grpc-protocolbuffers	3.700s
@dictav
dictav / Dockerfile
Created February 6, 2017 03:41
GCC + Go
FROM ubuntu
RUN apt update && apt install -y curl cmake golang git
RUN curl -O https://storage.googleapis.com/golang/go1.8rc3.linux-amd64.tar.gz &&\
tar xvf go1.8rc3.linux-amd64.tar.gz &&\
mv go /usr/local/go
@dictav
dictav / go-vimrc
Created February 7, 2017 04:10
vimrc to format go file.
let g:go_fmt_commands = 0 "disable builtin :Fmt
Plug 'haya14busa/vim-gofmt', { 'for': ['go'] }
let g:gofmt_formatters = [
\ { 'cmd': 'goimports', 'args': ['-w'] },
\ { 'cmd': 'gotypeconv', 'args': ['-w'] },
\ ]
Plug 'fatih/vim-go', { 'for': ['go'] }
let g:go_fmt_command = 'gofmtrlx'
let g:go_metalinter_autosave = 1 "enable auto :GoMetaLinter on save

GoGenerator generates code that can not be built if the definition file uses the type of another namespace. I compared four proposals to solve this problem.

  • Proposal 1: Add options to namespace
  • Proposal 2: Add base_namespace keyword
  • Proposal 3: Refer to GOPATH
  • Proposal 4: Use command line flag

TL;DR

All proposals, it has some issues, can solve the problem. And I recommend that use command line flag.