File: lsResponseMessage.h

package info (click to toggle)
asymptote 2.85%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 43,264 kB
  • sloc: cpp: 210,491; ansic: 98,376; python: 14,568; javascript: 6,629; sh: 4,301; perl: 1,566; lisp: 1,505; makefile: 764; yacc: 554; lex: 446; xml: 182; objc: 177
file content (71 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include "serializer.h"
#include "lsRequestId.h"
#include "LibLsp/JsonRpc/message.h"
#include "LibLsp/lsp/method_type.h"


struct ResponseInMessage :public LspMessage {

        lsRequestId id;
        std::string m_methodType;

        virtual  MethodType GetMethodType() const override
        {
                return m_methodType.data();
        };
        virtual  void SetMethodType(MethodType _type) override
        {
                m_methodType = _type;
        };

        Kind GetKid() override
        {
                return  RESPONCE_MESSAGE;
        }
        virtual  bool IsErrorType()
        {
                return false;
        }
};
template <class TDerived >
struct BaseResponseMessage : ResponseInMessage {

        void ReflectWriter(Writer& writer) override {
                Reflect(writer, static_cast<TDerived&>(*this));
        }
        static std::unique_ptr<LspMessage> ReflectReader(Reader& visitor) {

                TDerived* temp = new TDerived();
                std::unique_ptr<TDerived>  message = std::unique_ptr<TDerived>(temp);
                // Reflect may throw and *message will be partially deserialized.
                Reflect(visitor, static_cast<TDerived&>(*temp));
                return message;
        }

};


template <class T, class TDerived >
struct ResponseMessage : BaseResponseMessage<TDerived> {
        T result;
        void swap(ResponseMessage<T, TDerived>& arg) noexcept
        {
                std::swap(result, arg.result);
                this->id.swap(arg.id);
                this->m_methodType.swap(arg.m_methodType);
        }
};

template <class T, class TDerived >
struct ResponseError : BaseResponseMessage<TDerived> {
        T error;
        bool IsErrorType() override { return true; }
        void swap(ResponseError<T, TDerived>& arg) noexcept
        {

                this->id.swap(arg.id);
                this->m_methodType.swap(arg.m_methodType);
                std::swap(error, arg.error);
        }
};