text:
@interface JWPopoverController ()

@end

@implementation JWPopoverController

@synthesize contentViewController = _contentViewController;
@synthesize contentView = _contentView;
@synthesize innerCornerRadius = _innerCornerRadius;
@synthesize titleText = _titleText;
@synthesize titleColor = _titleColor;
@synthesize titleFont = _titleFont;
@synthesize arrowPosition = _arrowPosition;

- (id)init {
	if ((self = [super init])) {
        self.modelPresent = YES;
        self.innerCornerRadius = 0;//默认是5,里面的圆角
        self.outterCornerRadius = 0; //外面的圆角
        self.arrowHeight = 8;
        self.arrowWidth = 14;
        self.titleColor = [UIColor whiteColor];
        self.titleFont = [UIFont boldSystemFontOfSize:14];
        self.view.backgroundColor = [UIColor clearColor];
        self.arrowPosition = JWPopoverArrowPositionVertical;
        self.popoverBaseColor = [UIColor blackColor];
        screenRect = [[UIScreen mainScreen] bounds];
        if(self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
            screenRect.size.width = [[UIScreen mainScreen] bounds].size.height;
            screenRect.size.height = [[UIScreen mainScreen] bounds].size.width;
        }
        self.view.frame = screenRect;

        titleLabelheight = 0;
	}
	return self;
}

- (id)initWithContentViewController:(UIViewController*)viewController
{
    self = [self init];

    self.contentViewController = viewController;
    self.contentView = viewController.view;

    return self;
}

- (id)initWithView:(UIView*)view
{
    self = [self init];
    self.contentView = view;

    return self;
}

-(void)loadView{
    [super loadView];
    JWPopoverTouchView *touchView = [[JWPopoverTouchView alloc] init];
    touchView.frame = self.view.frame;
    touchView.delegate = self;
    self.view = touchView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (void) showPopoverWithTouch:(UIEvent*)senderEvent
{
    UIView *senderView = [[senderEvent.allTouches anyObject] view];
    CGPoint applicationFramePoint = CGPointMake(screenRect.origin.x,0-screenRect.origin.y);
    //CGPoint senderLocationInWindowPoint = [[[UIApplication sharedApplication] keyWindow] convertPoint:applicationFramePoint fromView:senderView];
    UIWindow *appWindow = [[UIApplication sharedApplication] keyWindow];
    CGPoint senderLocationInWindowPoint = [appWindow.rootViewController.view convertPoint:applicationFramePoint fromView:senderView];
    CGRect senderFrame = [[[senderEvent.allTouches anyObject] view] frame];
    senderFrame.origin.x = senderLocationInWindowPoint.x;
    senderFrame.origin.y = senderLocationInWindowPoint.y;
    CGPoint senderPoint = [self senderPointFromSenderRect:senderFrame];
    [self showPopoverWithPoint:senderPoint];
}

- (void) showPopoverWithCell:(UITableViewCell*)senderCell
{
    UIView *senderView = senderCell.superview;
    CGPoint applicationFramePoint = CGPointMake(screenRect.origin.x,0-screenRect.origin.y);
    CGPoint senderLocationInWindowPoint = [[[UIApplication sharedApplication] keyWindow] convertPoint:applicationFramePoint fromView:senderView];
    CGRect senderFrame = senderCell.frame;
    senderFrame.origin.x = senderLocationInWindowPoint.x;
    senderFrame.origin.y = senderLocationInWindowPoint.y + senderFrame.origin.y;
    CGPoint senderPoint = [self senderPointFromSenderRect:senderFrame];
    [self showPopoverWithPoint:senderPoint];
}

- (void) showPopoverWithRect:(CGRect)senderRect onView:(UIView *)view
{
    if (view) {//如果显示在某个视图上
        screenRect = view.bounds;
        self.view.frame = screenRect;
    }
    CGPoint senderPoint = [self senderPointFromSenderRect:senderRect];
    [self showPopoverWithPoint:senderPoint onView:view];
}

- (void) showPopoverWithPoint:(CGPoint)senderPoint{
    [self showPopoverWithPoint:senderPoint onView:nil];
}

- (void) showPopoverWithPoint:(CGPoint)senderPoint onView:(UIView *)view
{
    if(self.titleText){
        titleLabelheight = TITLE_LABEL_HEIGHT;
    }

    CGRect contentViewFrame = [self contentFrameRect:self.contentView.frame senderPoint:senderPoint];

    int backgroundPositionX = 0;
    int backgroundPositionY = 0;
    if(arrowDirection == JWPopoverArrowDirectionLeft){
        backgroundPositionX = self.arrowWidth;
    }
    if(arrowDirection == JWPopoverArrowDirectionTop){
        backgroundPositionY = self.arrowHeight;
    }

    UILabel *titleLabel;
    if(self.titleText){
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(backgroundPositionX, backgroundPositionY, contentViewFrame.size.width+MARGIN*2, TITLE_LABEL_HEIGHT+MARGIN)];
        titleLabel.textColor = self.titleColor;
        titleLabel.text = self.titleText;
        titleLabel.backgroundColor = [UIColor clearColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = self.titleFont;
    }
    contentViewFrame.origin.x = backgroundPositionX+MARGIN;
    contentViewFrame.origin.y = backgroundPositionY+titleLabelheight+MARGIN;

    self.contentView.frame = contentViewFrame;

    CALayer * contentViewLayer = [self.contentView layer];
    [contentViewLayer setMasksToBounds:YES];
    [contentViewLayer setCornerRadius:self.innerCornerRadius];

    popoverView = [[JWPopoverPopoverView alloc] init];
    popoverView.arrowHeight = self.arrowHeight;
    popoverView.arrowWidth = self.arrowWidth;
    popoverView.arrowDirection = arrowDirection;
    popoverView.arrowPosition = self.arrowPosition;
    popoverView.arrowPoint = senderPoint;
    popoverView.alpha = 0;
    popoverView.frame = [self popoverFrameRect:contentViewFrame senderPoint:senderPoint];
    if(self.outterCornerRadius == .0){
        self.outterCornerRadius = self.innerCornerRadius;
    }else{
        if (self.outterCornerRadius <= self.innerCornerRadius) {
            self.outterCornerRadius = self.innerCornerRadius + 5;
        }
    }
    popoverView.cornerRadius = self.outterCornerRadius;
    popoverView.baseColor = self.popoverBaseColor;
    [popoverView addSubview:self.contentView];
    [popoverView addSubview:titleLabel];

    if (self.showShadow) {
        CALayer* layer = popoverView.layer;
        layer.shadowOffset = CGSizeMake(0, 2);
        layer.shadowColor = [[UIColor blackColor] CGColor];
        layer.shadowOpacity = 0.5;
    }

    [self.view addSubview:popoverView];

    UIWindow *appWindow = [[UIApplication sharedApplication] keyWindow];
    if (view) {
        [view addSubview:self.view];
    }else{
        [appWindow.rootViewController.view addSubview:self.view];
    }

    [UIView animateWithDuration:0.0
                          delay:0.0
                        options:UIViewAnimationOptionAllowAnimatedContent
                     animations:^{
                         popoverView.alpha = 1;
                     }
                     completion:^(BOOL finished) {
                     }
     ];
}

- (void) dismissPopoverAnimatd:(BOOL)animated
{
    if (self.view) {
        if(animated) {
            [UIView animateWithDuration:0.2
                                  delay:0.0
                                options:UIViewAnimationOptionAllowAnimatedContent
                             animations:^{
                                 popoverView.alpha = 0;
                             }
                             completion:^(BOOL finished) {
                                 [self.contentViewController viewDidDisappear:animated];
                                 popoverView=nil;
                                 [self.view removeFromSuperview];
                                 self.contentViewController = nil;
                                 self.titleText = nil;
                                 self.titleColor = nil;
                                 self.titleFont = nil;
                             }
             ];
        }else{
            [self.contentViewController viewDidDisappear:animated];
            popoverView=nil;
            [self.view removeFromSuperview];
            self.contentViewController = nil;
            self.titleText = nil;
            self.titleColor = nil;
            self.titleFont = nil;
        }

    }
}

- (CGRect) contentFrameRect:(CGRect)contentFrame senderPoint:(CGPoint)senderPoint
{
    CGRect contentFrameRect = contentFrame;
    float screenWidth = screenRect.size.width;
    float screenHeight = screenRect.size.height - screenRect.origin.y;

    contentFrameRect.origin.x = MARGIN;
    contentFrameRect.origin.y = MARGIN;

    if(self.arrowPosition == JWPopoverArrowPositionVertical){
        if(contentFrameRect.size.width > self.view.frame.size.width - (OUTER_MARGIN*2+MARGIN*2)){
            contentFrameRect.size.width = self.view.frame.size.width - (OUTER_MARGIN*2+MARGIN*2);
        }

        float popoverY;
        float popoverHeight = contentFrameRect.size.height+titleLabelheight+(self.arrowHeight+MARGIN*2);//pop+title+margin+contentHeight + margin

        if(arrowDirection == JWPopoverArrowDirectionTop){
            popoverY = senderPoint.y+ARROW_MARGIN;
            if((popoverY+popoverHeight) > screenHeight){
                contentFrameRect.size.height = screenHeight - (screenRect.origin.y + popoverY + titleLabelheight + (OUTER_MARGIN*2+MARGIN*2));
            }
        }

        if(arrowDirection == JWPopoverArrowDirectionBottom){
            popoverY = senderPoint.y - ARROW_MARGIN;
            float statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
            if((popoverY-popoverHeight) < statusBarHeight){
                contentFrameRect.size.height = popoverY - (statusBarHeight + self.arrowHeight + screenRect.origin.y + titleLabelheight + (OUTER_MARGIN+MARGIN*2));
            }
        }
    }else if(self.arrowPosition == JWPopoverArrowPositionHorizontal){
        if(contentFrameRect.size.height > screenHeight - (OUTER_MARGIN*2+MARGIN*2)){
            contentFrameRect.size.height = screenHeight - (OUTER_MARGIN*2+MARGIN*2);
        }

        float popoverX;
        float popoverWidth = contentFrameRect.size.width+(self.arrowWidth+MARGIN*2);

        if(arrowDirection == JWPopoverArrowDirectionLeft){
            popoverX = senderPoint.x + ARROW_MARGIN;
            if((popoverX+popoverWidth)> screenWidth - (OUTER_MARGIN*2+MARGIN*2)){
                contentFrameRect.size.width = screenWidth - popoverX - self.arrowWidth - (OUTER_MARGIN*2+MARGIN*2);
            }
        }

        if(arrowDirection == JWPopoverArrowDirectionRight){
            popoverX = senderPoint.x - ARROW_MARGIN;
            if((popoverX-popoverWidth) < screenRect.origin.x+(OUTER_MARGIN*2+MARGIN*2)){
                contentFrameRect.size.width = popoverX - self.arrowWidth - (OUTER_MARGIN*2+MARGIN*2);
            }
        }

    }

    return contentFrameRect;
}

- (CGRect)popoverFrameRect:(CGRect)contentFrame senderPoint:(CGPoint)senderPoint
{
    CGRect popoverRect;
    float popoverWidth;
    float popoverHeight;
    float popoverX;
    float popoverY;

    if(self.arrowPosition == JWPopoverArrowPositionVertical){

        popoverWidth = contentFrame.size.width+MARGIN*2;
        popoverHeight = contentFrame.size.height+titleLabelheight+(self.arrowHeight+MARGIN*2);

        popoverX = senderPoint.x - (popoverWidth/2);
        if(popoverX < OUTER_MARGIN) {
            popoverX = OUTER_MARGIN;
        } else if((popoverX + popoverWidth)>self.view.frame.size.width) {
            popoverX = self.view.frame.size.width - (popoverWidth+OUTER_MARGIN);
        }

        if(arrowDirection == JWPopoverArrowDirectionBottom){
            popoverY = senderPoint.y - popoverHeight - ARROW_MARGIN;
        }else{
            popoverY = senderPoint.y + ARROW_MARGIN;
        }

        popoverRect = CGRectMake(popoverX, popoverY, popoverWidth, popoverHeight);

    }else if(self.arrowPosition == JWPopoverArrowPositionHorizontal){

        popoverWidth = contentFrame.size.width+self.arrowWidth+MARGIN*2;
        popoverHeight = contentFrame.size.height+titleLabelheight+MARGIN*2;

        if(arrowDirection == JWPopoverArrowDirectionRight){
            popoverX = senderPoint.x - popoverWidth - ARROW_MARGIN;
        }else{
            popoverX = senderPoint.x + ARROW_MARGIN;
        }

        popoverY = senderPoint.y - (popoverHeight/2);
        if(popoverY < OUTER_MARGIN){
            popoverY = OUTER_MARGIN;
        }else if((popoverY + popoverHeight)>self.view.frame.size.height){
            popoverY = self.view.frame.size.height - (popoverHeight+OUTER_MARGIN);
        }

        popoverRect = CGRectMake(popoverX, popoverY, popoverWidth, popoverHeight);

    }

    return popoverRect;

}

- (CGPoint)senderPointFromSenderRect:(CGRect)senderRect
{
    CGPoint senderPoint;
    [self checkArrowPosition:senderRect];

    if(arrowDirection == JWPopoverArrowDirectionTop){
        senderPoint = CGPointMake(senderRect.origin.x + (senderRect.size.width/2), senderRect.origin.y + senderRect.size.height);
    }else if(arrowDirection == JWPopoverArrowDirectionBottom){
        senderPoint = CGPointMake(senderRect.origin.x + (senderRect.size.width/2), senderRect.origin.y);
    }else if(arrowDirection == JWPopoverArrowDirectionRight){
        senderPoint = CGPointMake(senderRect.origin.x, senderRect.origin.y + (senderRect.size.height/2));
        senderPoint.y = senderPoint.y + screenRect.origin.y;
    }else if(arrowDirection == JWPopoverArrowDirectionLeft){
        senderPoint = CGPointMake(senderRect.origin.x + senderRect.size.width, senderRect.origin.y + (senderRect.size.height/2));
        senderPoint.y = senderPoint.y + screenRect.origin.y;
    }

    return senderPoint;
}

- (void) checkArrowPosition:(CGRect)senderRect
{
    float clearSpaceA=0;
    float clearSpaceB=0;
    if(self.arrowPosition == JWPopoverArrowPositionVertical){
        if(!arrowDirection){
            clearSpaceA = screenRect.origin.y + senderRect.origin.y;
            clearSpaceB = screenRect.size.height - (senderRect.origin.y+senderRect.size.height);
            if(clearSpaceA> clearSpaceB){
                if(clearSpaceA < titleLabelheight+10){//如果垂直方向间距空间过小,尝试箭头水平布局。
                    self.arrowPosition = JWPopoverArrowPositionHorizontal;
                    [self checkArrowPosition:senderRect];
                }else{
                    arrowDirection = JWPopoverArrowDirectionBottom;
                }
            }else{
                if(clearSpaceB < titleLabelheight+10){
                    self.arrowPosition = JWPopoverArrowPositionHorizontal;
                    [self checkArrowPosition:senderRect];
                }else{
                    arrowDirection = JWPopoverArrowDirectionTop;
                }
            }
        }

    }else if(self.arrowPosition == JWPopoverArrowPositionHorizontal){

        if(!arrowDirection){
            clearSpaceA = screenRect.origin.x + senderRect.origin.x;
            clearSpaceB = screenRect.size.width - (senderRect.origin.x+senderRect.size.width);
            if(clearSpaceA> clearSpaceB){
                if(clearSpaceA < 40){//如果水平间距过小,则尝试垂直布局
                    self.arrowPosition = JWPopoverArrowPositionVertical;
                    [self checkArrowPosition:senderRect];
                }else{
                    arrowDirection = JWPopoverArrowDirectionRight;
                }
            }else{
                if(clearSpaceB < 40){
                    self.arrowPosition = JWPopoverArrowPositionVertical;
                    [self checkArrowPosition:senderRect];
                }else{
                    arrowDirection = JWPopoverArrowDirectionLeft;
                }
            }
        }

    }
}

#pragma mark -TSPopoverTouchesDelegate
-(BOOL)popoverIsModelPresentWhenTouch{
    [self dismissPopoverAnimatd:YES];
    return self.modelPresent;
}

@end


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE252_Unchecked_Return_Value__wchar_t_sscanf_15.c
Label Definition File: CWE252_Unchecked_Return_Value.label.xml
Template File: point-flaw-15.tmpl.c
*/
/*
 * @description
 * CWE: 252 Unchecked Return Value
 * Sinks: sscanf
 *    GoodSink: Check if swscanf() fails
 *    BadSink : Do not check if swscanf() fails
 * Flow Variant: 15 Control flow: switch(6)
 *
 * */

#include "std_testcase.h"

#ifndef _WIN32
#include <wchar.h>
#endif

#define SRC L"sscanf"

#ifndef OMITBAD

void CWE252_Unchecked_Return_Value__wchar_t_sscanf_15_bad()
{
    switch(6)
    {
    case 6:
    {
        /* By initializing dataBuffer, we ensure this will not be the
         * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgetws() and other variants */
        wchar_t dataBuffer[100] = L"";
        wchar_t * data = dataBuffer;
        /* FLAW: Do not check the return value */
        swscanf(SRC, L"%99s\0", data);
    }
    break;
    default:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    }
}

#endif /* OMITBAD */

#ifndef OMITGOOD

/* good1() changes the switch to switch(5) */
static void good1()
{
    switch(5)
    {
    case 6:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    default:
    {
        /* By initializing dataBuffer, we ensure this will not be the
         * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgetws() and other variants */
        wchar_t dataBuffer[100] = L"";
        wchar_t * data = dataBuffer;
        /* FIX: check the return value */
        if (swscanf(SRC, L"%99s\0", data) == EOF)
        {
            printLine("swscanf failed!");
        }
    }
    break;
    }
}

/* good2() reverses the blocks in the switch */
static void good2()
{
    switch(6)
    {
    case 6:
    {
        /* By initializing dataBuffer, we ensure this will not be the
         * CWE 690 (Unchecked Return Value To NULL Pointer) flaw for fgetws() and other variants */
        wchar_t dataBuffer[100] = L"";
        wchar_t * data = dataBuffer;
        /* FIX: check the return value */
        if (swscanf(SRC, L"%99s\0", data) == EOF)
        {
            printLine("swscanf failed!");
        }
    }
    break;
    default:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    }
}

void CWE252_Unchecked_Return_Value__wchar_t_sscanf_15_good()
{
    good1();
    good2();
}

#endif /* OMITGOOD */

/* Below is the main(). It is only used when building this testcase on
   its own for testing or for building a binary to use in testing binary
   analysis tools. It is not used when compiling all the testcases as one
   application, which is how source code analysis tools are tested. */

#ifdef INCLUDEMAIN

int main(int argc, char * argv[])
{
    /* seed randomness */
    srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
    printLine("Calling good()...");
    CWE252_Unchecked_Return_Value__wchar_t_sscanf_15_good();
    printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
    printLine("Calling bad()...");
    CWE252_Unchecked_Return_Value__wchar_t_sscanf_15_bad();
    printLine("Finished bad()");
#endif /* OMITBAD */
    return 0;
}

#endif

redpajama_set_name: RedPajamaGithub


text:
using System;
using OrigoDB.Core;
using Twitter.Core;

namespace Twitter.Ui
{
    class Program
    {
        static void Main(string[] args)
        {
            var db = Db.For<TwitterVerse>();

            //Add some data if the db is empty
            if (db.AllUserIds().Count == 0) Setup(db);

            Console.WriteLine("Users:");
            foreach (var user in db.AllUserIds())
            {
                Console.WriteLine(user);
            }

            Console.WriteLine("Tweets:");
            foreach (var tweet in db.AllTweets())
            {
                Console.WriteLine("Id: " + tweet.Id);
                Console.WriteLine("By: " + tweet.UserId);
                Console.WriteLine("At: " + tweet.Posted);
                Console.WriteLine("Status: " + tweet.Status);
                Console.WriteLine("Favorites:" + String.Join(", ", tweet.Favoriteers));
                Console.WriteLine("Retweets: " + String.Join(", ", tweet.Retweeters));
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }

        private static void Setup(TwitterVerse db)
        {
            db.AddUser("batman");
            db.AddUser("joker");
            db.AddUser("robin");

            db.Follow("joker", "batman");
            db.Follow("batman", "robin");

            var tweetId = db.Tweet("batman", "Holy batwings, this bacon is delicious!", DateTime.Now);
            db.Retweet("robin", tweetId);
            db.Tweet("robin", "Did you see that @batman?", DateTime.Now);
            db.Tweet("batman", "I feel silly wearing this outfit", DateTime.Now);
            tweetId = db.Tweet("joker", "You won't escape this time @batman", DateTime.Now);
            db.Favorite("batman", tweetId);
        }

    }
}


text:
// Code generated by protoc-gen-go.
// source: ChatService.proto
// DO NOT EDIT!

/*
Package proto is a generated protocol buffer package.

It is generated from these files:
	ChatService.proto

It has these top-level messages:
	None
	RequestAuthorize
	ResponseAuthorize
	RequestConnect
	Command
	CommandSay
	CommandChangeNick
	CommandJoinChannel
	CommandLeaveChannel
	CommandExit
	Event
	EventNone
	EventJoin
	EventLeave
	EventLog
*/
package proto

import proto1 "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"

import (
	context "golang.org/x/net/context"
	grpc "google.golang.org/grpc"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto1.Marshal
var _ = fmt.Errorf
var _ = math.Inf

type None struct {
}

func (m *None) Reset()         { *m = None{} }
func (m *None) String() string { return proto1.CompactTextString(m) }
func (*None) ProtoMessage()    {}

type RequestAuthorize struct {
	Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}

func (m *RequestAuthorize) Reset()         { *m = RequestAuthorize{} }
func (m *RequestAuthorize) String() string { return proto1.CompactTextString(m) }
func (*RequestAuthorize) ProtoMessage()    {}

type ResponseAuthorize struct {
	SessionId uint32 `protobuf:"varint,1,opt,name=session_id" json:"session_id,omitempty"`
	Name      string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
}

func (m *ResponseAuthorize) Reset()         { *m = ResponseAuthorize{} }
func (m *ResponseAuthorize) String() string { return proto1.CompactTextString(m) }
func (*ResponseAuthorize) ProtoMessage()    {}

type RequestConnect struct {
	SessionId uint32 `protobuf:"varint,1,opt,name=session_id" json:"session_id,omitempty"`
}

func (m *RequestConnect) Reset()         { *m = RequestConnect{} }
func (m *RequestConnect) String() string { return proto1.CompactTextString(m) }
func (*RequestConnect) ProtoMessage()    {}

type Command struct {
	SessionId uint32 `protobuf:"varint,1,opt,name=session_id" json:"session_id,omitempty"`
	// Types that are valid to be assigned to Command:
	//	*Command_Say
	//	*Command_Nick
	//	*Command_Join
	//	*Command_Leave
	//	*Command_Exit
	Command isCommand_Command `protobuf_oneof:"command"`
}

func (m *Command) Reset()         { *m = Command{} }
func (m *Command) String() string { return proto1.CompactTextString(m) }
func (*Command) ProtoMessage()    {}

type isCommand_Command interface {
	isCommand_Command()
}

type Command_Say struct {
	Say *CommandSay `protobuf:"bytes,2,opt,name=say,oneof"`
}
type Command_Nick struct {
	Nick *CommandChangeNick `protobuf:"bytes,3,opt,name=nick,oneof"`
}
type Command_Join struct {
	Join *CommandJoinChannel `protobuf:"bytes,4,opt,name=join,oneof"`
}
type Command_Leave struct {
	Leave *CommandLeaveChannel `protobuf:"bytes,5,opt,name=leave,oneof"`
}
type Command_Exit struct {
	Exit *CommandExit `protobuf:"bytes,6,opt,name=exit,oneof"`
}

func (*Command_Say) isCommand_Command()   {}
func (*Command_Nick) isCommand_Command()  {}
func (*Command_Join) isCommand_Command()  {}
func (*Command_Leave) isCommand_Command() {}
func (*Command_Exit) isCommand_Command()  {}

func (m *Command) GetCommand() isCommand_Command {
	if m != nil {
		return m.Command
	}
	return nil
}

func (m *Command) GetSay() *CommandSay {
	if x, ok := m.GetCommand().(*Command_Say); ok {
		return x.Say
	}
	return nil
}

func (m *Command) GetNick() *CommandChangeNick {
	if x, ok := m.GetCommand().(*Command_Nick); ok {
		return x.Nick
	}
	return nil
}

func (m *Command) GetJoin() *CommandJoinChannel {
	if x, ok := m.GetCommand().(*Command_Join); ok {
		return x.Join
	}
	return nil
}

func (m *Command) GetLeave() *CommandLeaveChannel {
	if x, ok := m.GetCommand().(*Command_Leave); ok {
		return x.Leave
	}
	return nil
}

func (m *Command) GetExit() *CommandExit {
	if x, ok := m.GetCommand().(*Command_Exit); ok {
		return x.Exit
	}
	return nil
}

// XXX_OneofFuncs is for the internal use of the proto package.
func (*Command) XXX_OneofFuncs() (func(msg proto1.Message, b *proto1.Buffer) error, func(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error), []interface{}) {
	return _Command_OneofMarshaler, _Command_OneofUnmarshaler, []interface{}{
		(*Command_Say)(nil),
		(*Command_Nick)(nil),
		(*Command_Join)(nil),
		(*Command_Leave)(nil),
		(*Command_Exit)(nil),
	}
}

func _Command_OneofMarshaler(msg proto1.Message, b *proto1.Buffer) error {
	m := msg.(*Command)
	// command
	switch x := m.Command.(type) {
	case *Command_Say:
		b.EncodeVarint(2<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Say); err != nil {
			return err
		}
	case *Command_Nick:
		b.EncodeVarint(3<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Nick); err != nil {
			return err
		}
	case *Command_Join:
		b.EncodeVarint(4<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Join); err != nil {
			return err
		}
	case *Command_Leave:
		b.EncodeVarint(5<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Leave); err != nil {
			return err
		}
	case *Command_Exit:
		b.EncodeVarint(6<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Exit); err != nil {
			return err
		}
	case nil:
	default:
		return fmt.Errorf("Command.Command has unexpected type %T", x)
	}
	return nil
}

func _Command_OneofUnmarshaler(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error) {
	m := msg.(*Command)
	switch tag {
	case 2: // command.say
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(CommandSay)
		err := b.DecodeMessage(msg)
		m.Command = &Command_Say{msg}
		return true, err
	case 3: // command.nick
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(CommandChangeNick)
		err := b.DecodeMessage(msg)
		m.Command = &Command_Nick{msg}
		return true, err
	case 4: // command.join
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(CommandJoinChannel)
		err := b.DecodeMessage(msg)
		m.Command = &Command_Join{msg}
		return true, err
	case 5: // command.leave
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(CommandLeaveChannel)
		err := b.DecodeMessage(msg)
		m.Command = &Command_Leave{msg}
		return true, err
	case 6: // command.exit
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(CommandExit)
		err := b.DecodeMessage(msg)
		m.Command = &Command_Exit{msg}
		return true, err
	default:
		return false, nil
	}
}

type CommandSay struct {
	Message     string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
	ChannelName string `protobuf:"bytes,2,opt,name=channel_name" json:"channel_name,omitempty"`
}

func (m *CommandSay) Reset()         { *m = CommandSay{} }
func (m *CommandSay) String() string { return proto1.CompactTextString(m) }
func (*CommandSay) ProtoMessage()    {}

type CommandChangeNick struct {
	Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}

func (m *CommandChangeNick) Reset()         { *m = CommandChangeNick{} }
func (m *CommandChangeNick) String() string { return proto1.CompactTextString(m) }
func (*CommandChangeNick) ProtoMessage()    {}

type CommandJoinChannel struct {
	Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}

func (m *CommandJoinChannel) Reset()         { *m = CommandJoinChannel{} }
func (m *CommandJoinChannel) String() string { return proto1.CompactTextString(m) }
func (*CommandJoinChannel) ProtoMessage()    {}

type CommandLeaveChannel struct {
	Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}

func (m *CommandLeaveChannel) Reset()         { *m = CommandLeaveChannel{} }
func (m *CommandLeaveChannel) String() string { return proto1.CompactTextString(m) }
func (*CommandLeaveChannel) ProtoMessage()    {}

type CommandExit struct {
}

func (m *CommandExit) Reset()         { *m = CommandExit{} }
func (m *CommandExit) String() string { return proto1.CompactTextString(m) }
func (*CommandExit) ProtoMessage()    {}

type Event struct {
	// Types that are valid to be assigned to Event:
	//	*Event_None
	//	*Event_Join
	//	*Event_Leave
	//	*Event_Log
	Event isEvent_Event `protobuf_oneof:"event"`
}

func (m *Event) Reset()         { *m = Event{} }
func (m *Event) String() string { return proto1.CompactTextString(m) }
func (*Event) ProtoMessage()    {}

type isEvent_Event interface {
	isEvent_Event()
}

type Event_None struct {
	None *EventNone `protobuf:"bytes,1,opt,name=none,oneof"`
}
type Event_Join struct {
	Join *EventJoin `protobuf:"bytes,2,opt,name=join,oneof"`
}
type Event_Leave struct {
	Leave *EventLeave `protobuf:"bytes,3,opt,name=leave,oneof"`
}
type Event_Log struct {
	Log *EventLog `protobuf:"bytes,4,opt,name=log,oneof"`
}

func (*Event_None) isEvent_Event()  {}
func (*Event_Join) isEvent_Event()  {}
func (*Event_Leave) isEvent_Event() {}
func (*Event_Log) isEvent_Event()   {}

func (m *Event) GetEvent() isEvent_Event {
	if m != nil {
		return m.Event
	}
	return nil
}

func (m *Event) GetNone() *EventNone {
	if x, ok := m.GetEvent().(*Event_None); ok {
		return x.None
	}
	return nil
}

func (m *Event) GetJoin() *EventJoin {
	if x, ok := m.GetEvent().(*Event_Join); ok {
		return x.Join
	}
	return nil
}

func (m *Event) GetLeave() *EventLeave {
	if x, ok := m.GetEvent().(*Event_Leave); ok {
		return x.Leave
	}
	return nil
}

func (m *Event) GetLog() *EventLog {
	if x, ok := m.GetEvent().(*Event_Log); ok {
		return x.Log
	}
	return nil
}

// XXX_OneofFuncs is for the internal use of the proto package.
func (*Event) XXX_OneofFuncs() (func(msg proto1.Message, b *proto1.Buffer) error, func(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error), []interface{}) {
	return _Event_OneofMarshaler, _Event_OneofUnmarshaler, []interface{}{
		(*Event_None)(nil),
		(*Event_Join)(nil),
		(*Event_Leave)(nil),
		(*Event_Log)(nil),
	}
}

func _Event_OneofMarshaler(msg proto1.Message, b *proto1.Buffer) error {
	m := msg.(*Event)
	// event
	switch x := m.Event.(type) {
	case *Event_None:
		b.EncodeVarint(1<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.None); err != nil {
			return err
		}
	case *Event_Join:
		b.EncodeVarint(2<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Join); err != nil {
			return err
		}
	case *Event_Leave:
		b.EncodeVarint(3<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Leave); err != nil {
			return err
		}
	case *Event_Log:
		b.EncodeVarint(4<<3 | proto1.WireBytes)
		if err := b.EncodeMessage(x.Log); err != nil {
			return err
		}
	case nil:
	default:
		return fmt.Errorf("Event.Event has unexpected type %T", x)
	}
	return nil
}

func _Event_OneofUnmarshaler(msg proto1.Message, tag, wire int, b *proto1.Buffer) (bool, error) {
	m := msg.(*Event)
	switch tag {
	case 1: // event.none
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(EventNone)
		err := b.DecodeMessage(msg)
		m.Event = &Event_None{msg}
		return true, err
	case 2: // event.join
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(EventJoin)
		err := b.DecodeMessage(msg)
		m.Event = &Event_Join{msg}
		return true, err
	case 3: // event.leave
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(EventLeave)
		err := b.DecodeMessage(msg)
		m.Event = &Event_Leave{msg}
		return true, err
	case 4: // event.log
		if wire != proto1.WireBytes {
			return true, proto1.ErrInternalBadWireType
		}
		msg := new(EventLog)
		err := b.DecodeMessage(msg)
		m.Event = &Event_Log{msg}
		return true, err
	default:
		return false, nil
	}
}

type EventNone struct {
}

func (m *EventNone) Reset()         { *m = EventNone{} }
func (m *EventNone) String() string { return proto1.CompactTextString(m) }
func (*EventNone) ProtoMessage()    {}

type EventJoin struct {
	Name    string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Channel string `protobuf:"bytes,2,opt,name=channel" json:"channel,omitempty"`
}

func (m *EventJoin) Reset()         { *m = EventJoin{} }
func (m *EventJoin) String() string { return proto1.CompactTextString(m) }
func (*EventJoin) ProtoMessage()    {}

type EventLeave struct {
	Name    string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
	Channel string `protobuf:"bytes,2,opt,name=channel" json:"channel,omitempty"`
}

func (m *EventLeave) Reset()         { *m = EventLeave{} }
func (m *EventLeave) String() string { return proto1.CompactTextString(m) }
func (*EventLeave) ProtoMessage()    {}

type EventLog struct {
	Timestamp string `protobuf:"bytes,1,opt,name=timestamp" json:"timestamp,omitempty"`
	Name      string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
	Message   string `protobuf:"bytes,3,opt,name=message" json:"message,omitempty"`
	Channel   string `protobuf:"bytes,4,opt,name=channel" json:"channel,omitempty"`
}

func (m *EventLog) Reset()         { *m = EventLog{} }
func (m *EventLog) String() string { return proto1.CompactTextString(m) }
func (*EventLog) ProtoMessage()    {}

// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConn

// Client API for SimpleChat service

type SimpleChatClient interface {
	Authorize(ctx context.Context, in *RequestAuthorize, opts ...grpc.CallOption) (*ResponseAuthorize, error)
	Connect(ctx context.Context, in *RequestConnect, opts ...grpc.CallOption) (SimpleChat_ConnectClient, error)
	SendCommand(ctx context.Context, in *Command, opts ...grpc.CallOption) (*None, error)
}

type simpleChatClient struct {
	cc *grpc.ClientConn
}

func NewSimpleChatClient(cc *grpc.ClientConn) SimpleChatClient {
	return &simpleChatClient{cc}
}

func (c *simpleChatClient) Authorize(ctx context.Context, in *RequestAuthorize, opts ...grpc.CallOption) (*ResponseAuthorize, error) {
	out := new(ResponseAuthorize)
	err := grpc.Invoke(ctx, "/proto.SimpleChat/Authorize", in, out, c.cc, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func (c *simpleChatClient) Connect(ctx context.Context, in *RequestConnect, opts ...grpc.CallOption) (SimpleChat_ConnectClient, error) {
	stream, err := grpc.NewClientStream(ctx, &_SimpleChat_serviceDesc.Streams[0], c.cc, "/proto.SimpleChat/Connect", opts...)
	if err != nil {
		return nil, err
	}
	x := &simpleChatConnectClient{stream}
	if err := x.ClientStream.SendMsg(in); err != nil {
		return nil, err
	}
	if err := x.ClientStream.CloseSend(); err != nil {
		return nil, err
	}
	return x, nil
}

type SimpleChat_ConnectClient interface {
	Recv() (*Event, error)
	grpc.ClientStream
}

type simpleChatConnectClient struct {
	grpc.ClientStream
}

func (x *simpleChatConnectClient) Recv() (*Event, error) {
	m := new(Event)
	if err := x.ClientStream.RecvMsg(m); err != nil {
		return nil, err
	}
	return m, nil
}

func (c *simpleChatClient) SendCommand(ctx context.Context, in *Command, opts ...grpc.CallOption) (*None, error) {
	out := new(None)
	err := grpc.Invoke(ctx, "/proto.SimpleChat/SendCommand", in, out, c.cc, opts...)
	if err != nil {
		return nil, err
	}
	return out, nil
}

// Server API for SimpleChat service

type SimpleChatServer interface {
	Authorize(context.Context, *RequestAuthorize) (*ResponseAuthorize, error)
	Connect(*RequestConnect, SimpleChat_ConnectServer) error
	SendCommand(context.Context, *Command) (*None, error)
}

func RegisterSimpleChatServer(s *grpc.Server, srv SimpleChatServer) {
	s.RegisterService(&_SimpleChat_serviceDesc, srv)
}

func _SimpleChat_Authorize_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) {
	in := new(RequestAuthorize)
	if err := codec.Unmarshal(buf, in); err != nil {
		return nil, err
	}
	out, err := srv.(SimpleChatServer).Authorize(ctx, in)
	if err != nil {
		return nil, err
	}
	return out, nil
}

func _SimpleChat_Connect_Handler(srv interface{}, stream grpc.ServerStream) error {
	m := new(RequestConnect)
	if err := stream.RecvMsg(m); err != nil {
		return err
	}
	return srv.(SimpleChatServer).Connect(m, &simpleChatConnectServer{stream})
}

type SimpleChat_ConnectServer interface {
	Send(*Event) error
	grpc.ServerStream
}

type simpleChatConnectServer struct {
	grpc.ServerStream
}

func (x *simpleChatConnectServer) Send(m *Event) error {
	return x.ServerStream.SendMsg(m)
}

func _SimpleChat_SendCommand_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) {
	in := new(Command)
	if err := codec.Unmarshal(buf, in); err != nil {
		return nil, err
	}
	out, err := srv.(SimpleChatServer).SendCommand(ctx, in)
	if err != nil {
		return nil, err
	}
	return out, nil
}

var _SimpleChat_serviceDesc = grpc.ServiceDesc{
	ServiceName: "proto.SimpleChat",
	HandlerType: (*SimpleChatServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Authorize",
			Handler:    _SimpleChat_Authorize_Handler,
		},
		{
			MethodName: "SendCommand",
			Handler:    _SimpleChat_SendCommand_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "Connect",
			Handler:       _SimpleChat_Connect_Handler,
			ServerStreams: true,
		},
	},
}