aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nimpb/compiler/compiler.nim27
-rw-r--r--nimpb/compiler/generator.nim8
-rw-r--r--nimpb/json.nim3
-rw-r--r--nimpb/nimpb.nim3
-rw-r--r--nimpb/utils.nim2
5 files changed, 43 insertions, 0 deletions
diff --git a/nimpb/compiler/compiler.nim b/nimpb/compiler/compiler.nim
index b52a4d6..cbaec0d 100644
--- a/nimpb/compiler/compiler.nim
+++ b/nimpb/compiler/compiler.nim
@@ -1,3 +1,6 @@
+## This module implements functionality for finding and invoking the protoc
+## compiler.
+
import macros
import os
import osproc
@@ -15,6 +18,18 @@ when isNimpbProtocAvailable:
import nimpb_protoc
proc findCompiler*(): string =
+ ## Find the protoc compiler binary.
+ ##
+ ## This proc tries to find the protoc executable. The locations in order of
+ ## trying are:
+ ##
+ ## 1. If ``NIMPB_PROTOC`` environment variable is set, use it as the path to
+ ## protoc executable
+ ## 2. Use ``os.findExe()`` to search for the executable
+ ## 3. If `nimpb_protoc` nimble package is available, try to use the protoc
+ ## executable from it
+ ##
+ ## If the executable cannot be found, an exception is raised.
result = ""
if existsEnv("NIMPB_PROTOC"):
@@ -49,12 +64,24 @@ Now you have three options to make this work:
raise newException(Exception, msg)
proc myTempDir(): string =
+ # TODO: make this unique
result = getTempDir() / "nimpb_protoc_tmp"
proc compileProtos*(protos: openArray[string],
includes: openArray[string],
outdir: string,
serviceGenerator: ServiceGenerator = nil) =
+ ## Compile proto files to Nim code.
+ ##
+ ## This proc invokes the protoc compiler to do the actual job.
+ ##
+ ## Compiles the files passed in ``protos``, using include directories
+ ## specified in ``includes``. Note that the include directories need to
+ ## include the directories where the input files live. The generated files
+ ## are written to ``outdir``.
+ ##
+ ## If ``serviceGenerator`` is not nil, it will be called for each defined
+ ## service.
let command = findCompiler()
var args: seq[string] = @[]
diff --git a/nimpb/compiler/generator.nim b/nimpb/compiler/generator.nim
index 7590bde..70dcde0 100644
--- a/nimpb/compiler/generator.nim
+++ b/nimpb/compiler/generator.nim
@@ -1,3 +1,5 @@
+## This module implements Nim code generation from protoc output.
+
import algorithm
import os
import pegs
@@ -1301,6 +1303,12 @@ proc processFileDescriptorSet*(filename: string,
outdir: string,
protos: openArray[string],
serviceGenerator: ServiceGenerator) =
+ ## Generate code from a FileDescriptorSet stored in a file.
+ ##
+ ## ``filename`` is the full path to the file storing the FileDescriptorSet.
+ ## ``outdir`` is the output directory for files. ``protos`` contains the
+ ## paths to the proto files which were passed to the protoc compiler.
+ ## ``serviceGenerator`` specifies the user supplied service generator.
let s = newFileStream(filename, fmRead)
let fileSet = readgoogle_protobuf_FileDescriptorSet(s)
diff --git a/nimpb/json.nim b/nimpb/json.nim
index b611cdf..8d34fc3 100644
--- a/nimpb/json.nim
+++ b/nimpb/json.nim
@@ -1,3 +1,6 @@
+## This module implements protobuf3 JSON serializing and deserializing for some
+## primitive types.
+
import base64
import math
import std/json
diff --git a/nimpb/nimpb.nim b/nimpb/nimpb.nim
index 228ac35..21c44f5 100644
--- a/nimpb/nimpb.nim
+++ b/nimpb/nimpb.nim
@@ -1,3 +1,6 @@
+## This module implements the basic Protocol Buffers serialization and
+## deserialization primitives which are used by the generated code.
+
import endians
import intsets
import std/json
diff --git a/nimpb/utils.nim b/nimpb/utils.nim
index 8220ef2..40d9443 100644
--- a/nimpb/utils.nim
+++ b/nimpb/utils.nim
@@ -1,3 +1,5 @@
+## This module implements some misc utilities.
+
import strutils
proc toCamelCase*(s: string): string =