# 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
        pair: seq[vac_remotelog_RemoteLog_Pair]
        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]

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*(): 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]): 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.pair = @[]
    result.tail = @[]

proc clearpair*(message: vac_remotelog_RemoteLog) =
    message.pair = @[]
    clearFields(message, [1])

proc haspair*(message: vac_remotelog_RemoteLog): bool =
    result = hasField(message, 1) or (len(message.pair) > 0)

proc setpair*(message: vac_remotelog_RemoteLog, value: seq[vac_remotelog_RemoteLog_Pair]) =
    message.pair = value
    setField(message, 1)

proc addpair*(message: vac_remotelog_RemoteLog, value: vac_remotelog_RemoteLog_Pair) =
    add(message.pair, value)

proc pair*(message: vac_remotelog_RemoteLog): seq[vac_remotelog_RemoteLog_Pair] {.inline.} =
    message.pair

proc `pair=`*(message: vac_remotelog_RemoteLog, value: seq[vac_remotelog_RemoteLog_Pair]) {.inline.} =
    setpair(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 =
    for value in message.pair:
        result = result + sizeOfTag(1, WireType.LengthDelimited)
        result = result + sizeOfLengthDelimited(sizeOfvac_remotelog_RemoteLog_Pair(value))
    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) =
    for value in message.pair:
        writeMessage(stream, value, 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)
            addpair(result, newvac_remotelog_RemoteLog_Pair(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 len(message.pair) > 0:
        let arr = newJArray()
        for value in message.pair:
            add(arr, toJson(value))
        result["pair"] = arr
    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, "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))
    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)


