Add remote log protobuf and gen

This commit is contained in:
Oskar Thoren 2019-09-06 11:00:29 +02:00
parent 34f7b25c81
commit 5e6a8f593d
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
3 changed files with 416 additions and 0 deletions

View File

@ -0,0 +1,21 @@
syntax = "proto3";
package vac.remotelog;
// XXX: Move out of ns_service.proto?
// Two parts: body and tail (+ header?)
message RemoteLog {
Body body = 1;
bytes tail = 2;
// Order preserved
message Body {
repeated Pair pair = 1;
}
// XXX: Potentially extended with embedded data
message Pair {
bytes remoteHash = 1;
bytes localHash = 2;
}
}

View File

@ -0,0 +1,384 @@
# Generated by protoc_gen_nim. Do not edit!
import base64
import intsets
import json
import strutils
import nimpb/nimpb
import nimpb/json as nimpb_json
type
vac_remotelog_RemoteLog* = ref vac_remotelog_RemoteLogObj
vac_remotelog_RemoteLogObj* = object of Message
body: vac_remotelog_RemoteLog_Body
tail: seq[byte]
vac_remotelog_RemoteLog_Pair* = ref vac_remotelog_RemoteLog_PairObj
vac_remotelog_RemoteLog_PairObj* = object of Message
remoteHash: seq[byte]
localHash: seq[byte]
vac_remotelog_RemoteLog_Body* = ref vac_remotelog_RemoteLog_BodyObj
vac_remotelog_RemoteLog_BodyObj* = object of Message
pair: seq[vac_remotelog_RemoteLog_Pair]
proc newvac_remotelog_RemoteLog_Pair*(): vac_remotelog_RemoteLog_Pair
proc newvac_remotelog_RemoteLog_Pair*(data: string): vac_remotelog_RemoteLog_Pair
proc newvac_remotelog_RemoteLog_Pair*(data: seq[byte]): vac_remotelog_RemoteLog_Pair
proc writevac_remotelog_RemoteLog_Pair*(stream: Stream, message: vac_remotelog_RemoteLog_Pair)
proc readvac_remotelog_RemoteLog_Pair*(stream: Stream): vac_remotelog_RemoteLog_Pair
proc sizeOfvac_remotelog_RemoteLog_Pair*(message: vac_remotelog_RemoteLog_Pair): uint64
proc toJson*(message: vac_remotelog_RemoteLog_Pair): JsonNode
proc parsevac_remotelog_RemoteLog_Pair*(obj: JsonNode): vac_remotelog_RemoteLog_Pair
proc newvac_remotelog_RemoteLog_Body*(): vac_remotelog_RemoteLog_Body
proc newvac_remotelog_RemoteLog_Body*(data: string): vac_remotelog_RemoteLog_Body
proc newvac_remotelog_RemoteLog_Body*(data: seq[byte]): vac_remotelog_RemoteLog_Body
proc writevac_remotelog_RemoteLog_Body*(stream: Stream, message: vac_remotelog_RemoteLog_Body)
proc readvac_remotelog_RemoteLog_Body*(stream: Stream): vac_remotelog_RemoteLog_Body
proc sizeOfvac_remotelog_RemoteLog_Body*(message: vac_remotelog_RemoteLog_Body): uint64
proc toJson*(message: vac_remotelog_RemoteLog_Body): JsonNode
proc parsevac_remotelog_RemoteLog_Body*(obj: JsonNode): vac_remotelog_RemoteLog_Body
proc newvac_remotelog_RemoteLog*(): vac_remotelog_RemoteLog
proc newvac_remotelog_RemoteLog*(data: string): vac_remotelog_RemoteLog
proc newvac_remotelog_RemoteLog*(data: seq[byte]): vac_remotelog_RemoteLog
proc writevac_remotelog_RemoteLog*(stream: Stream, message: vac_remotelog_RemoteLog)
proc readvac_remotelog_RemoteLog*(stream: Stream): vac_remotelog_RemoteLog
proc sizeOfvac_remotelog_RemoteLog*(message: vac_remotelog_RemoteLog): uint64
proc toJson*(message: vac_remotelog_RemoteLog): JsonNode
proc parsevac_remotelog_RemoteLog*(obj: JsonNode): vac_remotelog_RemoteLog
proc fullyQualifiedName*(T: typedesc[vac_remotelog_RemoteLog_Pair]): string = "vac.remotelog.RemoteLog.Pair"
proc readvac_remotelog_RemoteLog_PairImpl(stream: Stream): Message = readvac_remotelog_RemoteLog_Pair(stream)
proc writevac_remotelog_RemoteLog_PairImpl(stream: Stream, msg: Message) = writevac_remotelog_RemoteLog_Pair(stream, vac_remotelog_RemoteLog_Pair(msg))
proc toJsonvac_remotelog_RemoteLog_PairImpl(msg: Message): JsonNode = toJson(vac_remotelog_RemoteLog_Pair(msg))
proc fromJsonvac_remotelog_RemoteLog_PairImpl(node: JsonNode): Message = parsevac_remotelog_RemoteLog_Pair(node)
proc vac_remotelog_RemoteLog_PairProcs*(): MessageProcs =
result.readImpl = readvac_remotelog_RemoteLog_PairImpl
result.writeImpl = writevac_remotelog_RemoteLog_PairImpl
result.toJsonImpl = toJsonvac_remotelog_RemoteLog_PairImpl
result.fromJsonImpl = fromJsonvac_remotelog_RemoteLog_PairImpl
proc newvac_remotelog_RemoteLog_Pair*(): vac_remotelog_RemoteLog_Pair =
new(result)
initMessage(result[])
result.procs = vac_remotelog_RemoteLog_PairProcs()
result.remoteHash = @[]
result.localHash = @[]
proc clearremoteHash*(message: vac_remotelog_RemoteLog_Pair) =
message.remoteHash = @[]
proc setremoteHash*(message: vac_remotelog_RemoteLog_Pair, value: seq[byte]) =
message.remoteHash = value
proc remoteHash*(message: vac_remotelog_RemoteLog_Pair): seq[byte] {.inline.} =
message.remoteHash
proc `remoteHash=`*(message: vac_remotelog_RemoteLog_Pair, value: seq[byte]) {.inline.} =
setremoteHash(message, value)
proc clearlocalHash*(message: vac_remotelog_RemoteLog_Pair) =
message.localHash = @[]
proc setlocalHash*(message: vac_remotelog_RemoteLog_Pair, value: seq[byte]) =
message.localHash = value
proc localHash*(message: vac_remotelog_RemoteLog_Pair): seq[byte] {.inline.} =
message.localHash
proc `localHash=`*(message: vac_remotelog_RemoteLog_Pair, value: seq[byte]) {.inline.} =
setlocalHash(message, value)
proc sizeOfvac_remotelog_RemoteLog_Pair*(message: vac_remotelog_RemoteLog_Pair): uint64 =
if len(message.remoteHash) > 0:
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfBytes(message.remoteHash)
if len(message.localHash) > 0:
result = result + sizeOfTag(2, WireType.LengthDelimited)
result = result + sizeOfBytes(message.localHash)
result = result + sizeOfUnknownFields(message)
proc writevac_remotelog_RemoteLog_Pair*(stream: Stream, message: vac_remotelog_RemoteLog_Pair) =
if len(message.remoteHash) > 0:
protoWriteBytes(stream, message.remoteHash, 1)
if len(message.localHash) > 0:
protoWriteBytes(stream, message.localHash, 2)
writeUnknownFields(stream, message)
proc readvac_remotelog_RemoteLog_Pair*(stream: Stream): vac_remotelog_RemoteLog_Pair =
result = newvac_remotelog_RemoteLog_Pair()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.LengthDelimited)
setremoteHash(result, protoReadBytes(stream))
of 2:
expectWireType(wireType, WireType.LengthDelimited)
setlocalHash(result, protoReadBytes(stream))
else: readUnknownField(stream, result, tag)
proc toJson*(message: vac_remotelog_RemoteLog_Pair): JsonNode =
result = newJObject()
if len(message.remoteHash) > 0:
result["remoteHash"] = %message.remoteHash
if len(message.localHash) > 0:
result["localHash"] = %message.localHash
proc parsevac_remotelog_RemoteLog_Pair*(obj: JsonNode): vac_remotelog_RemoteLog_Pair =
result = newvac_remotelog_RemoteLog_Pair()
var node: JsonNode
if obj.kind != JObject:
raise newException(nimpb_json.ParseError, "object expected")
node = getJsonField(obj, "remoteHash", "remoteHash")
if node != nil and node.kind != JNull:
setremoteHash(result, parseBytes(node))
node = getJsonField(obj, "localHash", "localHash")
if node != nil and node.kind != JNull:
setlocalHash(result, parseBytes(node))
proc serialize*(message: vac_remotelog_RemoteLog_Pair): string =
let
ss = newStringStream()
writevac_remotelog_RemoteLog_Pair(ss, message)
result = ss.data
proc newvac_remotelog_RemoteLog_Pair*(data: string): vac_remotelog_RemoteLog_Pair =
let
ss = newStringStream(data)
result = readvac_remotelog_RemoteLog_Pair(ss)
proc newvac_remotelog_RemoteLog_Pair*(data: seq[byte]): vac_remotelog_RemoteLog_Pair =
let
ss = newStringStream(cast[string](data))
result = readvac_remotelog_RemoteLog_Pair(ss)
proc fullyQualifiedName*(T: typedesc[vac_remotelog_RemoteLog_Body]): string = "vac.remotelog.RemoteLog.Body"
proc readvac_remotelog_RemoteLog_BodyImpl(stream: Stream): Message = readvac_remotelog_RemoteLog_Body(stream)
proc writevac_remotelog_RemoteLog_BodyImpl(stream: Stream, msg: Message) = writevac_remotelog_RemoteLog_Body(stream, vac_remotelog_RemoteLog_Body(msg))
proc toJsonvac_remotelog_RemoteLog_BodyImpl(msg: Message): JsonNode = toJson(vac_remotelog_RemoteLog_Body(msg))
proc fromJsonvac_remotelog_RemoteLog_BodyImpl(node: JsonNode): Message = parsevac_remotelog_RemoteLog_Body(node)
proc vac_remotelog_RemoteLog_BodyProcs*(): MessageProcs =
result.readImpl = readvac_remotelog_RemoteLog_BodyImpl
result.writeImpl = writevac_remotelog_RemoteLog_BodyImpl
result.toJsonImpl = toJsonvac_remotelog_RemoteLog_BodyImpl
result.fromJsonImpl = fromJsonvac_remotelog_RemoteLog_BodyImpl
proc newvac_remotelog_RemoteLog_Body*(): vac_remotelog_RemoteLog_Body =
new(result)
initMessage(result[])
result.procs = vac_remotelog_RemoteLog_BodyProcs()
result.pair = @[]
proc clearpair*(message: vac_remotelog_RemoteLog_Body) =
message.pair = @[]
clearFields(message, [1])
proc haspair*(message: vac_remotelog_RemoteLog_Body): bool =
result = hasField(message, 1) or (len(message.pair) > 0)
proc setpair*(message: vac_remotelog_RemoteLog_Body, value: seq[vac_remotelog_RemoteLog_Pair]) =
message.pair = value
setField(message, 1)
proc addpair*(message: vac_remotelog_RemoteLog_Body, value: vac_remotelog_RemoteLog_Pair) =
add(message.pair, value)
proc pair*(message: vac_remotelog_RemoteLog_Body): seq[vac_remotelog_RemoteLog_Pair] {.inline.} =
message.pair
proc `pair=`*(message: vac_remotelog_RemoteLog_Body, value: seq[vac_remotelog_RemoteLog_Pair]) {.inline.} =
setpair(message, value)
proc sizeOfvac_remotelog_RemoteLog_Body*(message: vac_remotelog_RemoteLog_Body): uint64 =
for value in message.pair:
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfvac_remotelog_RemoteLog_Pair(value))
result = result + sizeOfUnknownFields(message)
proc writevac_remotelog_RemoteLog_Body*(stream: Stream, message: vac_remotelog_RemoteLog_Body) =
for value in message.pair:
writeMessage(stream, value, 1)
writeUnknownFields(stream, message)
proc readvac_remotelog_RemoteLog_Body*(stream: Stream): vac_remotelog_RemoteLog_Body =
result = newvac_remotelog_RemoteLog_Body()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.LengthDelimited)
let data = readLengthDelimited(stream)
addpair(result, newvac_remotelog_RemoteLog_Pair(data))
else: readUnknownField(stream, result, tag)
proc toJson*(message: vac_remotelog_RemoteLog_Body): JsonNode =
result = newJObject()
if len(message.pair) > 0:
let arr = newJArray()
for value in message.pair:
add(arr, toJson(value))
result["pair"] = arr
proc parsevac_remotelog_RemoteLog_Body*(obj: JsonNode): vac_remotelog_RemoteLog_Body =
result = newvac_remotelog_RemoteLog_Body()
var node: JsonNode
if obj.kind != JObject:
raise newException(nimpb_json.ParseError, "object expected")
node = getJsonField(obj, "pair", "pair")
if node != nil and node.kind != JNull:
if node.kind != JArray:
raise newException(ValueError, "not an array")
for value in node:
addpair(result, parsevac_remotelog_RemoteLog_Pair(value))
proc serialize*(message: vac_remotelog_RemoteLog_Body): string =
let
ss = newStringStream()
writevac_remotelog_RemoteLog_Body(ss, message)
result = ss.data
proc newvac_remotelog_RemoteLog_Body*(data: string): vac_remotelog_RemoteLog_Body =
let
ss = newStringStream(data)
result = readvac_remotelog_RemoteLog_Body(ss)
proc newvac_remotelog_RemoteLog_Body*(data: seq[byte]): vac_remotelog_RemoteLog_Body =
let
ss = newStringStream(cast[string](data))
result = readvac_remotelog_RemoteLog_Body(ss)
proc fullyQualifiedName*(T: typedesc[vac_remotelog_RemoteLog]): string = "vac.remotelog.RemoteLog"
proc readvac_remotelog_RemoteLogImpl(stream: Stream): Message = readvac_remotelog_RemoteLog(stream)
proc writevac_remotelog_RemoteLogImpl(stream: Stream, msg: Message) = writevac_remotelog_RemoteLog(stream, vac_remotelog_RemoteLog(msg))
proc toJsonvac_remotelog_RemoteLogImpl(msg: Message): JsonNode = toJson(vac_remotelog_RemoteLog(msg))
proc fromJsonvac_remotelog_RemoteLogImpl(node: JsonNode): Message = parsevac_remotelog_RemoteLog(node)
proc vac_remotelog_RemoteLogProcs*(): MessageProcs =
result.readImpl = readvac_remotelog_RemoteLogImpl
result.writeImpl = writevac_remotelog_RemoteLogImpl
result.toJsonImpl = toJsonvac_remotelog_RemoteLogImpl
result.fromJsonImpl = fromJsonvac_remotelog_RemoteLogImpl
proc newvac_remotelog_RemoteLog*(): vac_remotelog_RemoteLog =
new(result)
initMessage(result[])
result.procs = vac_remotelog_RemoteLogProcs()
result.body = nil
result.tail = @[]
proc clearbody*(message: vac_remotelog_RemoteLog) =
message.body = nil
clearFields(message, [1])
proc hasbody*(message: vac_remotelog_RemoteLog): bool =
result = hasField(message, 1)
proc setbody*(message: vac_remotelog_RemoteLog, value: vac_remotelog_RemoteLog_Body) =
message.body = value
setField(message, 1)
proc body*(message: vac_remotelog_RemoteLog): vac_remotelog_RemoteLog_Body {.inline.} =
message.body
proc `body=`*(message: vac_remotelog_RemoteLog, value: vac_remotelog_RemoteLog_Body) {.inline.} =
setbody(message, value)
proc cleartail*(message: vac_remotelog_RemoteLog) =
message.tail = @[]
proc settail*(message: vac_remotelog_RemoteLog, value: seq[byte]) =
message.tail = value
proc tail*(message: vac_remotelog_RemoteLog): seq[byte] {.inline.} =
message.tail
proc `tail=`*(message: vac_remotelog_RemoteLog, value: seq[byte]) {.inline.} =
settail(message, value)
proc sizeOfvac_remotelog_RemoteLog*(message: vac_remotelog_RemoteLog): uint64 =
if hasbody(message):
result = result + sizeOfTag(1, WireType.LengthDelimited)
result = result + sizeOfLengthDelimited(sizeOfvac_remotelog_RemoteLog_Body(message.body))
if len(message.tail) > 0:
result = result + sizeOfTag(2, WireType.LengthDelimited)
result = result + sizeOfBytes(message.tail)
result = result + sizeOfUnknownFields(message)
proc writevac_remotelog_RemoteLog*(stream: Stream, message: vac_remotelog_RemoteLog) =
if hasbody(message):
writeMessage(stream, message.body, 1)
if len(message.tail) > 0:
protoWriteBytes(stream, message.tail, 2)
writeUnknownFields(stream, message)
proc readvac_remotelog_RemoteLog*(stream: Stream): vac_remotelog_RemoteLog =
result = newvac_remotelog_RemoteLog()
while not atEnd(stream):
let
tag = readTag(stream)
wireType = wireType(tag)
case fieldNumber(tag)
of 0:
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.LengthDelimited)
let data = readLengthDelimited(stream)
setbody(result, newvac_remotelog_RemoteLog_Body(data))
of 2:
expectWireType(wireType, WireType.LengthDelimited)
settail(result, protoReadBytes(stream))
else: readUnknownField(stream, result, tag)
proc toJson*(message: vac_remotelog_RemoteLog): JsonNode =
result = newJObject()
if hasbody(message):
result["body"] = toJson(message.body)
if len(message.tail) > 0:
result["tail"] = %message.tail
proc parsevac_remotelog_RemoteLog*(obj: JsonNode): vac_remotelog_RemoteLog =
result = newvac_remotelog_RemoteLog()
var node: JsonNode
if obj.kind != JObject:
raise newException(nimpb_json.ParseError, "object expected")
node = getJsonField(obj, "body", "body")
if node != nil and node.kind != JNull:
setbody(result, parsevac_remotelog_RemoteLog_Body(node))
node = getJsonField(obj, "tail", "tail")
if node != nil and node.kind != JNull:
settail(result, parseBytes(node))
proc serialize*(message: vac_remotelog_RemoteLog): string =
let
ss = newStringStream()
writevac_remotelog_RemoteLog(ss, message)
result = ss.data
proc newvac_remotelog_RemoteLog*(data: string): vac_remotelog_RemoteLog =
let
ss = newStringStream(data)
result = readvac_remotelog_RemoteLog(ss)
proc newvac_remotelog_RemoteLog*(data: seq[byte]): vac_remotelog_RemoteLog =
let
ss = newStringStream(cast[string](data))
result = readvac_remotelog_RemoteLog(ss)

View File

@ -0,0 +1,11 @@
import asyncdispatch
import asynchttpserver
import httpclient
import json
import strutils
import remote_log_pb
import nimtwirp/nimtwirp
import nimtwirp/errors